Skip to content

Commit cb4cf5d

Browse files
committed
Merge branch 'develop' into release/2.x
2 parents 886b7e1 + 98f2b85 commit cb4cf5d

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ dependencies {
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'
3838
api group: 'io.github.amayaframework', name: 'amaya-http', version: '1.0.2'
39-
api group: 'io.github.amayaframework', name: 'amaya-context', version: '1.3.0'
39+
api group: 'io.github.amayaframework', name: 'amaya-context', version: '1.3.1'
4040
api group: 'io.github.amayaframework', name: 'amaya-server', version: '1.3.0'
4141
api group: 'io.github.amayaframework', name: 'amaya-application', version: '1.1.4'
42-
api group: 'io.github.amayaframework', name: 'amaya-web', version: '1.0.3'
42+
api group: 'io.github.amayaframework', name: 'amaya-web', version: '1.1.0'
4343
// DI
4444
compileOnly group: 'io.github.amayaframework', name: 'amaya-di', version: '2.3.3'
4545
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ public void sendError(HttpCode code) throws IOException {
149149
}
150150

151151
@Override
152-
public void sendRedirect(String location) throws IOException {
152+
public void sendRedirect(String location, boolean encode) throws IOException {
153153
Objects.requireNonNull(location);
154+
if (encode) {
155+
location = response.encodeRedirectURL(location);
156+
}
154157
response.sendRedirect(location);
155158
this.status = HttpCode.FOUND;
156159
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,37 @@ public interface HttpResponse extends Response, HttpTransaction {
128128
* the response should be considered to be committed and should not be written to.
129129
*
130130
* @param location the redirect location URL
131+
* @param encode the flag determines either url will be encoded with current session id
131132
* @throws IOException if an input or output exception occurs
132133
* @throws IllegalStateException if the response was committed or if a partial URL is given and cannot be converted
133134
* into a valid URL
134135
*/
135-
void sendRedirect(String location) throws IOException;
136+
void sendRedirect(String location, boolean encode) throws IOException;
137+
138+
/**
139+
* Sends a temporary redirect response to the client using the specified redirect location URL
140+
* and clears the buffer. The buffer will be replaced with the data set by this method. Calling this method sets
141+
* the status code to {@link HttpCode#FOUND}. This method can accept relative URLs;the servlet container must
142+
* convert the relative URL to an absolute URL before sending the response to the client.
143+
* If the location is relative without a leading '/' the container interprets it as relative to the current request
144+
* URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet
145+
* container root. If the location is relative with two leading '/' the container interprets it as a network-path
146+
* reference (see <a href="http://www.ietf.org/rfc/rfc3986.txt"> RFC 3986: Uniform Resource Identifier (URI):
147+
* Generic Syntax</a>, section 4.2 &quot;Relative Reference&quot;).
148+
* <p>
149+
* If the response has already been committed, this method throws an IllegalStateException. After using this method,
150+
* the response should be considered to be committed and should not be written to.
151+
* <p>
152+
* Does not encode redirect url.
153+
*
154+
* @param location the redirect location URL
155+
* @throws IOException if an input or output exception occurs
156+
* @throws IllegalStateException if the response was committed or if a partial URL is given and cannot be converted
157+
* into a valid URL
158+
*/
159+
default void sendRedirect(String location) throws IOException {
160+
sendRedirect(location, false);
161+
}
136162

137163
/**
138164
* Gets the supplier of trailer headers.

web/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
// Middlewares
3232
api group: 'com.github.romanqed', name: 'jconv', version: '1.1.0'
3333
// Amaya modules
34+
compileOnly project(':http')
3435
compileOnly project(':options')
3536
compileOnly project(':environment')
3637
compileOnly project(':service')

web/src/main/java/io/github/amayaframework/web/AbstractWebApplication.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.github.amayaframework.application.AbstractApplication;
55
import io.github.amayaframework.context.HttpContext;
66
import io.github.amayaframework.environment.Environment;
7+
import io.github.amayaframework.http.HttpVersion;
78
import io.github.amayaframework.options.GroupOptionSet;
89
import io.github.amayaframework.server.HttpServer;
910
import io.github.amayaframework.server.HttpServerConfig;
@@ -49,6 +50,13 @@ public void bind(InetSocketAddress address) {
4950
server.getConfig().addAddress(address);
5051
}
5152

53+
@Override
54+
public void bind(InetSocketAddress address, HttpVersion version) {
55+
Objects.requireNonNull(address);
56+
Objects.requireNonNull(version);
57+
server.getConfig().addAddress(address, version);
58+
}
59+
5260
@Override
5361
public void bind(int port) {
5462
if (port < 0 || port > 65535) {
@@ -57,6 +65,15 @@ public void bind(int port) {
5765
server.getConfig().addAddress(new InetSocketAddress(port));
5866
}
5967

68+
@Override
69+
public void bind(int port, HttpVersion version) {
70+
Objects.requireNonNull(version);
71+
if (port < 0 || port > 65535) {
72+
throw new IllegalArgumentException("Illegal port value: " + port);
73+
}
74+
server.getConfig().addAddress(new InetSocketAddress(port), version);
75+
}
76+
6077
@Override
6178
protected void doStart(Runnable1<HttpContext> handler) throws Throwable {
6279
this.manager.start();

web/src/main/java/io/github/amayaframework/web/WebApplication.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.romanqed.jfunc.Runnable2;
55
import io.github.amayaframework.application.Application;
66
import io.github.amayaframework.context.HttpContext;
7+
import io.github.amayaframework.http.HttpVersion;
78
import io.github.amayaframework.server.HttpServerConfig;
89

910
import java.net.InetSocketAddress;
@@ -22,18 +23,38 @@ public interface WebApplication extends Application<HttpContext> {
2223

2324
/**
2425
* Binds web application to given address.
26+
* If the implementation supports it, multiple bindings are possible.
2527
*
2628
* @param address the specified address that the server will listen to, must be non-null
2729
*/
2830
void bind(InetSocketAddress address);
2931

32+
/**
33+
* Binds web application to given address with the specified http version.
34+
* If the implementation supports it, multiple bindings are possible.
35+
*
36+
* @param address the specified address that the server will listen to, must be non-null
37+
* @param version the specified http version, must be non-null
38+
*/
39+
void bind(InetSocketAddress address, HttpVersion version);
40+
3041
/**
3142
* Binds web application to given port.
43+
* If the implementation supports it, multiple bindings are possible.
3244
*
3345
* @param port the specified port that the server will listen to
3446
*/
3547
void bind(int port);
3648

49+
/**
50+
* Binds web application to given port with the specified http version.
51+
* If the implementation supports it, multiple bindings are possible.
52+
*
53+
* @param port the specified port that the server will listen to
54+
* @param version the specified http version, must be non-null
55+
*/
56+
void bind(int port, HttpVersion version);
57+
3758
@Override
3859
void addHandler(Runnable2<HttpContext, Runnable1<HttpContext>> handler);
3960

web/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module io.github.amayaframework.web {
77
// Requires
88
requires com.github.romanqed.jfunc;
9+
requires io.github.amayaframework.http;
910
requires io.github.amayaframework.options;
1011
requires io.github.amayaframework.environment;
1112
requires io.github.amayaframework.service;

0 commit comments

Comments
 (0)