Skip to content

Commit eafd98b

Browse files
author
wangzihao
committed
fix: #50
1 parent 4f503c7 commit eafd98b

19 files changed

+403
-68
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
152152
<dependency>
153153
<groupId>com.github.wangzihaogithub</groupId>
154154
<artifactId>spring-boot-protocol</artifactId>
155-
<version>2.3.28</version>
155+
<version>2.3.29</version>
156156
</dependency>
157157
```
158158

@@ -164,7 +164,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
164164
<dependency>
165165
<groupId>com.github.wangzihaogithub</groupId>
166166
<artifactId>netty-servlet</artifactId>
167-
<version>2.3.28</version>
167+
<version>2.3.29</version>
168168
</dependency>
169169
```
170170

@@ -320,7 +320,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
320320
<dependency>
321321
<groupId>com.github.wangzihaogithub</groupId>
322322
<artifactId>spring-boot-protocol</artifactId>
323-
<version>2.3.28</version>
323+
<version>2.3.29</version>
324324
</dependency>
325325

326326
2.编写代码
@@ -400,7 +400,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
400400
<dependency>
401401
<groupId>com.github.wangzihaogithub</groupId>
402402
<artifactId>spring-boot-protocol</artifactId>
403-
<version>2.3.28</version>
403+
<version>2.3.29</version>
404404
</dependency>
405405

406406
2.编写代码
@@ -489,7 +489,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
489489
<dependency>
490490
<groupId>com.github.wangzihaogithub</groupId>
491491
<artifactId>spring-boot-protocol</artifactId>
492-
<version>2.3.28</version>
492+
<version>2.3.29</version>
493493
</dependency>
494494
495495
2.编写启动类

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.wangzihaogithub</groupId>
66
<artifactId>spring-boot-protocol</artifactId>
7-
<version>2.3.28</version>
7+
<version>2.3.29</version>
88
<packaging>jar</packaging>
99

1010
<name>Spring Boot Protocol</name>
@@ -49,7 +49,7 @@
4949
<connection>scm:git:https://github.com/wangzihaogithub/spring-boot-protocol.git</connection>
5050
<developerConnection>scm:git:git@github.com:wangzihaogithub/spring-boot-protocol.git</developerConnection>
5151
<url>git@github.com:wangzihaogithub/spring-boot-protocol.git</url>
52-
<tag>v2.3.28</tag>
52+
<tag>v2.3.29</tag>
5353
</scm>
5454

5555
<!-- 开发者信息 -->

src/main/java/com/github/netty/protocol/HttpServletProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.github.netty.core.util.ResourceManager;
1111
import com.github.netty.protocol.servlet.*;
1212
import com.github.netty.protocol.servlet.http2.H2Util;
13-
import com.github.netty.protocol.servlet.ssl.SslContextBuilders;
13+
import com.github.netty.protocol.servlet.SslContextBuilders;
1414
import com.github.netty.protocol.servlet.util.HttpConstants;
1515
import com.github.netty.protocol.servlet.util.*;
1616
import com.github.netty.protocol.servlet.websocket.WebSocketHandler;

src/main/java/com/github/netty/protocol/servlet/DefaultServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class DefaultServlet extends HttpServlet {
6666
private final Set<String> homePages = new LinkedHashSet<>(Arrays.asList("index.html", "index.htm", "index"));
6767
private String characterEncoding = "utf-8";
6868
private final Map<String, String> mimeTypeMappings = new CaseInsensitiveKeyMap<>();
69-
private final HttpHeaders responseHeaders = new DefaultHttpHeaders(false);
69+
private final HttpHeaders responseHeaders = new DefaultHttpHeaders();
7070

7171
public DefaultServlet() {
7272
DEFAULT_MIME_TYPE_MAPPINGS.forEach((k, v) -> mimeTypeMappings.put(k.toString(), v.toString()));

src/main/java/com/github/netty/protocol/servlet/NettyHttpResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class NettyHttpResponse implements HttpResponse, Recyclable, Flushable {
3636
private boolean writeSendFile = false;
3737

3838
public NettyHttpResponse() {
39-
this.headers = new DefaultHttpHeaders(false);
39+
this.headers = new DefaultHttpHeaders();
4040
this.version = HttpVersion.HTTP_1_1;
4141
this.status = DEFAULT_STATUS;
4242
this.decoderResult = DecoderResult.SUCCESS;

src/main/java/com/github/netty/protocol/servlet/NettyMessageToServletRunnable.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class NettyMessageToServletRunnable implements MessageToRunnable {
4242
private static final FullHttpResponse NOT_ACCEPTABLE_CLOSE = new DefaultFullHttpResponse(
4343
HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_ACCEPTABLE, Unpooled.EMPTY_BUFFER);
4444
private static final Set<HttpMethod> HTTP_METHOD_SET = new HashSet<>(9);
45+
private static final FastThreadLocal<List<Runnable>> ASYNC_CONTEXT_DISPATCH_THREAD_LOCAL = new FastThreadLocal<>();
4546

4647
static {
4748
EXPECTATION_FAILED.headers().set(CONTENT_LENGTH, 0);
@@ -66,7 +67,12 @@ public class NettyMessageToServletRunnable implements MessageToRunnable {
6667
private ServletHttpExchange exchange;
6768
private /*volatile */ HttpRunnable httpRunnable;
6869

69-
private static final FastThreadLocal<List<Runnable>> ASYNC_CONTEXT_DISPATCH_THREAD_LOCAL = new FastThreadLocal<>();
70+
public NettyMessageToServletRunnable(ServletContext servletContext, long maxContentLength, Protocol protocol, boolean ssl) {
71+
this.servletContext = servletContext;
72+
this.maxContentLength = maxContentLength;
73+
this.protocol = protocol;
74+
this.ssl = ssl;
75+
}
7076

7177
static boolean isCurrentRunAtRequesting() {
7278
return ASYNC_CONTEXT_DISPATCH_THREAD_LOCAL.get() != null;
@@ -79,13 +85,6 @@ static void addAsyncContextDispatch(Runnable runnable) {
7985
}
8086
}
8187

82-
public NettyMessageToServletRunnable(ServletContext servletContext, long maxContentLength, Protocol protocol, boolean ssl) {
83-
this.servletContext = servletContext;
84-
this.maxContentLength = maxContentLength;
85-
this.protocol = protocol;
86-
this.ssl = ssl;
87-
}
88-
8988
@Override
9089
public Runnable onMessage(ChannelHandlerContext context, Object msg) {
9190
ServletHttpExchange exchange = this.exchange;
@@ -252,7 +251,13 @@ public void run() {
252251
try {
253252
String requestURI = request.getRequestURI();
254253
if (servletContext.isMapperContextRootRedirectEnabled() && requestURI.equals(servletContext.getContextPath())) {
255-
response.sendRedirect(requestURI.concat("/"));
254+
StringBuilder redirectPath = RecyclableUtil.newStringBuilder();
255+
redirectPath.append(requestURI).append('/');
256+
String query = request.getQueryString();
257+
if (query != null) {
258+
redirectPath.append("?").append(query);
259+
}
260+
response.sendRedirect(redirectPath.toString());
256261
} else {
257262
dispatcher = request.getRequestDispatcher(requestURI);
258263
if (dispatcher == null) {

src/main/java/com/github/netty/protocol/servlet/ServletContext.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ protected Map<Charset, DefaultHttpDataFactory> initialValue() throws Exception {
8787
private Servlet defaultServlet = new DefaultServlet();
8888
private boolean enableLookupFlag = false;
8989
private boolean mapperContextRootRedirectEnabled = true;
90+
private boolean useRelativeRedirects = true;
9091
private boolean autoFlush;
9192
private String serverHeader;
9293
private CharSequence serverHeaderAscii;
@@ -197,6 +198,14 @@ public void setUploadFileTimeoutMs(long uploadFileTimeoutMs) {
197198
this.uploadFileTimeoutMs = uploadFileTimeoutMs;
198199
}
199200

201+
public boolean isUseRelativeRedirects() {
202+
return useRelativeRedirects;
203+
}
204+
205+
public void setUseRelativeRedirects(boolean useRelativeRedirects) {
206+
this.useRelativeRedirects = useRelativeRedirects;
207+
}
208+
200209
public boolean isMapperContextRootRedirectEnabled() {
201210
return mapperContextRootRedirectEnabled;
202211
}
@@ -701,6 +710,20 @@ public ServletSessionCookieConfig getSessionCookieConfig() {
701710
return sessionCookieConfig;
702711
}
703712

713+
public String getSessionCookieParamName() {
714+
String userSettingCookieName = sessionCookieConfig.getName();
715+
return userSettingCookieName != null && !userSettingCookieName.isEmpty() ?
716+
userSettingCookieName : HttpConstants.JSESSION_ID_COOKIE;
717+
}
718+
719+
public String getSessionUriParamName() {
720+
String userSettingCookieName = sessionCookieConfig.getName();
721+
if (userSettingCookieName == null || userSettingCookieName.isEmpty()) {
722+
userSettingCookieName = HttpConstants.JSESSION_ID_URL;
723+
}
724+
return userSettingCookieName;
725+
}
726+
704727
@Override
705728
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) {
706729
sessionTrackingModeSet = sessionTrackingModes;
@@ -714,7 +737,7 @@ public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
714737
@Override
715738
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
716739
if (sessionTrackingModeSet == null) {
717-
return getDefaultSessionTrackingModes();
740+
return defaultSessionTrackingModeSet;
718741
}
719742
return sessionTrackingModeSet;
720743
}

src/main/java/com/github/netty/protocol/servlet/ServletHttpAsyncRequest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public String getQueryString() {
130130
if (decodePathsQueryIndex != -1) {
131131
this.queryString = requestURI.substring(decodePathsQueryIndex + 1);
132132
}
133+
getQueryStringFlag = true;
133134
}
134135
return this.queryString;
135136
}
@@ -148,6 +149,7 @@ public String getRequestURI() {
148149
} else {
149150
this.requestURI = dispatchPath.substring(0, decodePathsQueryIndex);
150151
}
152+
getRequestURIFlag = true;
151153
}
152154
return this.requestURI;
153155
}
@@ -202,11 +204,6 @@ public Map<String, String[]> getParameterMap() {
202204
return parameterMap;
203205
}
204206

205-
public void setParameterMap(Map<String, String[]> parameterMap) {
206-
this.parameterMap = parameterMap;
207-
this.decodeParameterFlag = true;
208-
}
209-
210207
@Override
211208
public String getParameter(String name) {
212209
String[] values = getParameterMap().get(name);

src/main/java/com/github/netty/protocol/servlet/ServletHttpForwardRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public String getQueryString() {
127127
if (decodePathsQueryIndex != -1) {
128128
this.queryString = requestURI.substring(decodePathsQueryIndex + 1);
129129
}
130+
getQueryStringFlag = true;
130131
}
131132
return this.queryString;
132133
}
@@ -145,6 +146,7 @@ public String getRequestURI() {
145146
} else {
146147
this.requestURI = forwardPath.substring(0, decodePathsQueryIndex);
147148
}
149+
getRequestURIFlag = true;
148150
}
149151
return this.requestURI;
150152
}

src/main/java/com/github/netty/protocol/servlet/ServletHttpIncludeRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public String getQueryString() {
127127
if (decodePathsQueryIndex != -1) {
128128
this.queryString = requestURI.substring(decodePathsQueryIndex + 1);
129129
}
130+
getQueryStringFlag = true;
130131
}
131132
return this.queryString;
132133
}
@@ -145,6 +146,7 @@ public String getRequestURI() {
145146
} else {
146147
this.requestURI = includePath.substring(0, decodePathsQueryIndex);
147148
}
149+
getRequestURIFlag = true;
148150
}
149151
return this.requestURI;
150152
}

0 commit comments

Comments
 (0)