Skip to content

Commit fa49c64

Browse files
committed
Merge branch 'develop' into release/2.x
2 parents 7c91a46 + f504c05 commit fa49c64

File tree

12 files changed

+121
-6
lines changed

12 files changed

+121
-6
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ dependencies {
3535
api group: 'io.github.amayaframework', name: 'amaya-options', version: '1.2.1'
3636
api group: 'io.github.amayaframework', name: 'amaya-environment', version: '1.0.2'
3737
api group: 'io.github.amayaframework', name: 'amaya-service', version: '1.0.0'
38-
api group: 'io.github.amayaframework', name: 'amaya-context', version: '1.1.2'
39-
api group: 'io.github.amayaframework', name: 'amaya-server', version: '1.1.3'
38+
api group: 'io.github.amayaframework', name: 'amaya-http', version: '1.0.1'
39+
api group: 'io.github.amayaframework', name: 'amaya-context', version: '1.1.4'
40+
api group: 'io.github.amayaframework', name: 'amaya-server', version: '1.2.0'
4041
api group: 'io.github.amayaframework', name: 'amaya-application', version: '1.1.4'
41-
api group: 'io.github.amayaframework', name: 'amaya-web', version: '1.0.2'
42+
api group: 'io.github.amayaframework', name: 'amaya-web', version: '1.0.3'
4243
// DI
4344
compileOnly group: 'io.github.amayaframework', name: 'amaya-di', version: '2.3.3'
4445
}

context/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies {
2929
// Servlets
3030
compileOnly group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '5.0.0'
3131
// Http
32-
api group: 'io.github.amayaframework', name: 'amaya-http', version: '1.0.0'
32+
compileOnly project(':http')
3333
}
3434

3535
test {

context/src/main/java/io/github/amayaframework/context/AbstractHttpResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,27 @@ public HttpCode getStatus() {
123123

124124
@Override
125125
public void setStatus(HttpCode code) {
126+
if (!code.isSupported(version)) {
127+
throw new UnsupportedHttpDefinition(version, code);
128+
}
126129
response.setStatus(code.getCode());
127130
this.status = code;
128131
}
129132

130133
@Override
131134
public void sendError(HttpCode code, String message) throws IOException {
135+
if (!code.isSupported(version)) {
136+
throw new UnsupportedHttpDefinition(version, code);
137+
}
132138
response.sendError(code.getCode(), message);
133139
this.status = code;
134140
}
135141

136142
@Override
137143
public void sendError(HttpCode code) throws IOException {
144+
if (!code.isSupported(version)) {
145+
throw new UnsupportedHttpDefinition(version, code);
146+
}
138147
response.sendError(code.getCode());
139148
this.status = code;
140149
}

http/src/main/java/io/github/amayaframework/http/HttpVersion.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ public final class HttpVersion implements Comparable<HttpVersion> {
1212
public static final HttpVersion HTTP_1_0 = new HttpVersion("HTTP/1.0", 10);
1313
public static final HttpVersion HTTP_1_1 = new HttpVersion("HTTP/1.1", 11);
1414
public static final HttpVersion HTTP_2_0 = new HttpVersion("HTTP/2.0", 20);
15+
public static final HttpVersion HTTP_3_0 = new HttpVersion("HTTP/3.0", 30);
1516

1617
private static final Map<String, HttpVersion> VERSIONS = Map.of(
1718
"HTTP/1.0", HTTP_1_0,
1819
"HTTP/1", HTTP_1_0,
1920
"HTTP/1.1", HTTP_1_1,
2021
"HTTP/2.0", HTTP_2_0,
21-
"HTTP/2", HTTP_2_0
22+
"HTTP/2", HTTP_2_0,
23+
"HTTP/3.0", HTTP_3_0,
24+
"HTTP/3", HTTP_3_0
2225
);
2326
final String tag;
2427
final int number;
@@ -64,6 +67,9 @@ public static HttpVersion of(int number) {
6467
case 2:
6568
case 20:
6669
return HTTP_2_0;
70+
case 3:
71+
case 30:
72+
return HTTP_3_0;
6773
}
6874
return null;
6975
}

http/src/test/java/io/github/amayaframework/http/HttpVersionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,42 @@ public void testPredefined() {
2121
assertEquals(HttpVersion.HTTP_2_0, HttpVersion.of(20));
2222
assertEquals(HttpVersion.HTTP_2_0, HttpVersion.of("HTTP/2"));
2323
assertEquals(HttpVersion.HTTP_2_0, HttpVersion.of("HTTP/2.0"));
24+
// 3.0
25+
assertEquals(HttpVersion.HTTP_3_0, HttpVersion.of(3));
26+
assertEquals(HttpVersion.HTTP_3_0, HttpVersion.of(30));
27+
assertEquals(HttpVersion.HTTP_3_0, HttpVersion.of("HTTP/3"));
28+
assertEquals(HttpVersion.HTTP_3_0, HttpVersion.of("HTTP/3.0"));
2429
}
2530

2631
@Test
2732
public void testComparisons() {
2833
var http1 = HttpVersion.HTTP_1_0;
2934
var http11 = HttpVersion.HTTP_1_1;
3035
var http2 = HttpVersion.HTTP_2_0;
36+
var http3 = HttpVersion.HTTP_3_0;
37+
// http/1
3138
assertTrue(http1.before(http11));
3239
assertFalse(http1.after(http11));
3340
assertTrue(http1.before(http2));
3441
assertFalse(http1.after(http2));
42+
// http/1.1
3543
assertTrue(http11.after(http1));
3644
assertFalse(http11.before(http1));
3745
assertTrue(http11.before(http2));
3846
assertFalse(http11.after(http2));
47+
// http/2
3948
assertTrue(http2.after(http1));
4049
assertFalse(http2.before(http1));
4150
assertTrue(http2.after(http11));
4251
assertFalse(http2.before(http11));
52+
// http/3
53+
assertTrue(http3.after(http11));
54+
assertFalse(http3.before(http11));
55+
assertTrue(http3.after(http1));
56+
assertFalse(http3.before(http1));
57+
assertTrue(http3.after(http2));
58+
assertTrue(http3.after(http2));
59+
assertFalse(http3.before(http2));
4360
assertEquals(-1, http1.compareTo(http11));
4461
assertEquals(1, http11.compareTo(http1));
4562
}

server/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ dependencies {
2828
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'
2929
// JFunc
3030
api group: 'com.github.romanqed', name: 'jfunc', version: '1.1.4'
31+
// Amaya environment
32+
compileOnly project(':environment')
3133
// Amaya options
3234
compileOnly project(':options')
35+
// Amaya http lib
36+
compileOnly project(':http')
3337
// Amaya context
3438
compileOnly project(':context')
3539
// Amaya services

server/src/main/java/io/github/amayaframework/server/HttpServer.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
import com.github.romanqed.jfunc.Runnable1;
44
import io.github.amayaframework.context.HttpContext;
5+
import io.github.amayaframework.http.HttpVersion;
6+
7+
import java.net.InetSocketAddress;
58

69
/**
710
* An interface describing an abstract http server.
811
*/
912
public interface HttpServer extends Server<HttpContext> {
1013

14+
/**
15+
* Binds server to given {@link InetSocketAddress} address with the specified http version.
16+
* If the implementation supports it, multiple bindings are possible.
17+
*
18+
* @param address the specified address that the server will listen to, must be non-null
19+
* @param version the specified http version, must be non-null
20+
*/
21+
void bind(InetSocketAddress address, HttpVersion version);
22+
23+
/**
24+
* Binds server to given port with the specified http version.
25+
* If the implementation supports it, multiple bindings are possible.
26+
*
27+
* @param port the specified port that the server will listen to
28+
* @param version the specified http version, must be non-null
29+
*/
30+
void bind(int port, HttpVersion version);
31+
1132
/**
1233
* Gets http server config. Any config changes are reflected on the server and vice versa.
1334
*

server/src/main/java/io/github/amayaframework/server/HttpServerConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.github.amayaframework.http.HttpVersion;
44

5+
import java.net.InetSocketAddress;
6+
57
/**
68
* An interface describing the http server config.
79
*/
@@ -22,6 +24,14 @@ public interface HttpServerConfig extends ServerConfig {
2224
*/
2325
void setHttpVersion(HttpVersion version);
2426

27+
/**
28+
* Adds given address to listened set and starts listen it with specified http protocol.
29+
*
30+
* @param address the specified address to be listened, must be non-null
31+
* @param version the specified http version, must be non-null
32+
*/
33+
void addAddress(InetSocketAddress address, HttpVersion version);
34+
2535
/**
2636
* Gets the {@link MimeFormatter} instance used by server. The default value depends on the implementation.
2737
*

server/src/main/java/io/github/amayaframework/server/HttpServerFactory.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package io.github.amayaframework.server;
22

33
import io.github.amayaframework.context.HttpContext;
4+
import io.github.amayaframework.environment.Environment;
45
import io.github.amayaframework.options.OptionSet;
56

67
/**
78
* An interface describing an abstract {@link HttpServer} factory.
89
*/
910
public interface HttpServerFactory extends ServerFactory<HttpContext> {
1011

12+
/**
13+
* Creates a {@link HttpServer} instance with given options and environment.
14+
*
15+
* @param set the specified {@link OptionSet} instance, containing initial server options
16+
* @param env the specified {@link Environment} instance
17+
* @return ready to use, the properly configured {@link HttpServer} instance
18+
*/
19+
default HttpServer create(OptionSet set, Environment env) {
20+
return create(set);
21+
}
22+
1123
/**
1224
* Creates a {@link HttpServer} instance with given options.
1325
*
@@ -17,6 +29,17 @@ public interface HttpServerFactory extends ServerFactory<HttpContext> {
1729
@Override
1830
HttpServer create(OptionSet set);
1931

32+
/**
33+
* Creates a {@link HttpServer} instance with environment and default options,
34+
* defined by the factory implementation.
35+
*
36+
* @param env the specified {@link Environment} instance
37+
* @return ready to use, the properly configured {@link HttpServer} instance
38+
*/
39+
default HttpServer create(Environment env) {
40+
return create();
41+
}
42+
2043
/**
2144
* Creates a {@link HttpServer} instance with default options, defined by the factory implementation.
2245
*

server/src/main/java/io/github/amayaframework/server/ServerFactory.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.amayaframework.server;
22

33
import io.github.amayaframework.context.Context;
4+
import io.github.amayaframework.environment.Environment;
45
import io.github.amayaframework.options.OptionSet;
56

67
/**
@@ -10,6 +11,17 @@
1011
*/
1112
public interface ServerFactory<T extends Context> {
1213

14+
/**
15+
* Creates a {@link Server} instance with given options and environment.
16+
*
17+
* @param set the specified {@link OptionSet} instance, containing initial server options
18+
* @param env the specified {@link Environment} instance
19+
* @return ready to use, the properly configured {@link Server} instance
20+
*/
21+
default Server<T> create(OptionSet set, Environment env) {
22+
return create(set);
23+
}
24+
1325
/**
1426
* Creates a {@link Server} instance with given options.
1527
*
@@ -18,6 +30,16 @@ public interface ServerFactory<T extends Context> {
1830
*/
1931
Server<T> create(OptionSet set);
2032

33+
/**
34+
* Creates a {@link Server} instance with environment and default options, defined by the factory implementation.
35+
*
36+
* @param env the specified {@link Environment} instance
37+
* @return ready to use, the properly configured {@link Server} instance
38+
*/
39+
default Server<T> create(Environment env) {
40+
return create();
41+
}
42+
2143
/**
2244
* Creates a {@link Server} instance with default options, defined by the factory implementation.
2345
*

0 commit comments

Comments
 (0)