Skip to content

Commit

Permalink
Merge branch '2.2.2.RELEASE' into main
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	docs/Version.md
#	masker-rest-framework/pom.xml
#	masker-rest-jjwt/pom.xml
#	masker-rest-rsa/pom.xml
#	pom.xml
  • Loading branch information
jiashunx committed Aug 24, 2024
2 parents da0abe5 + 4a2e273 commit 900cf94
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- Websocket Server Framework
- 复用Http服务器端口发布Websocket服务(websocket服务可根据url进行请求分发)

- 版本清单(最新版本: <b>2.2.1.RELEASE</b>):
- 版本清单(最新版本: <b>2.2.2.RELEASE</b>):

- 参见: [Version.md][0]

Expand Down
9 changes: 9 additions & 0 deletions docs/Version.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

<h3 id="V">masker-rest版本清单</h3>

- [V2.2.2.RELEASE](#2.2.2)
- [V2.2.1.RELEASE](#2.2.1)
- [V2.2.0.RELEASE](#2.2.0)
- [V2.1.4.RELEASE](#2.1.4)
Expand Down Expand Up @@ -41,6 +42,14 @@
- [V1.1.0](#V1.1.0)
- [V1.0.0](#V1.0.0)

<h4 id="V2.2.2">V2.2.2.RELEASE</h4>

- fix: 修正application/x-www-form-urlencoded请求报文解析处理

- refactor: http请求报文解析优化

- refactor: 请求报错日志输出完整方法调用栈

<h4 id="V2.2.1">V2.2.1.RELEASE</h4>

- fix: 修复header方法处理逻辑(移除错误方法)
Expand Down
2 changes: 1 addition & 1 deletion masker-rest-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.github.jiashunx</groupId>
<artifactId>masker-rest</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.2.2.RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>masker-rest-framework</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Constants {
public static final String HTTP_HEADER_SERVER_STARTUP_TIME = "Server-Startup-Time";
public static final String HTTP_HEADER_SERVER_IDENTIFIER = "Server-Identifier";

public static final String CONTENT_TYPE_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
public static final String CONTENT_TYPE_MULTIPART_FORMDATA = "multipart/form-data";
public static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
public static final String CONTENT_TYPE_TEXT_PLAIN = "text/plain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object object) throws Exc
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
// super.exceptionCaught(ctx, cause);
logger.error("error occured, error reason: {}", cause.getMessage());
logger.error("error occurred", cause);
Channel channel = ctx.channel();
if (channel.isActive()) {
ctx.close();
Expand Down Expand Up @@ -307,18 +307,6 @@ private MRestRequest parseHttpRequest(ChannelHandlerContext ctx, FullHttpRequest
}
restRequest.setUrl(url);
restRequest.setUrlQuery(queryStringDecoder.rawQuery());

Map<String, List<String>> originParameters = queryStringDecoder.parameters();
restRequest.setOriginParameters(originParameters);
Map<String, String> parameters = new HashMap<>();
originParameters.forEach((key, value) -> {
String mergedVal = "";
if (value != null && !value.isEmpty()) {
mergedVal = value.get(value.size() - 1);
}
parameters.put(key, mergedVal);
});
restRequest.setParameters(parameters);
restRequest.setMethod(httpRequest.method());
restRequest.setHeaders(httpRequest.headers());
// 处理文件上传特定逻辑.
Expand All @@ -344,9 +332,40 @@ private MRestRequest parseHttpRequest(ChannelHandlerContext ctx, FullHttpRequest
if (byteSize >= 0) {
bodyBytes = new byte[byteSize];
httpRequest.content().readBytes(bodyBytes, 0, byteSize);
} else {
bodyBytes = new byte[0];
}
restRequest.setBodyBytes(bodyBytes);
}
// 参数解析
Map<String, List<String>> originParameters = queryStringDecoder.parameters();
restRequest.setOriginParameters(originParameters);
Map<String, String> parameters = new HashMap<>();
originParameters.forEach((key, value) -> {
String mergedVal = "";
if (value != null && !value.isEmpty()) {
mergedVal = value.get(value.size() - 1);
}
parameters.put(key, mergedVal);
});
String contentType = httpRequest.headers().get(Constants.HTTP_HEADER_CONTENT_TYPE);
if (Constants.CONTENT_TYPE_X_WWW_FORM_URLENCODED.equals(contentType)) {
String content = new String(restRequest.getBodyBytes(), StandardCharsets.UTF_8);
if (StringUtils.isNotEmpty(content)) {
String[] kvArr = new String(restRequest.getBodyBytes(), StandardCharsets.UTF_8).split("&");
for (String kv: kvArr) {
int i = kv.indexOf("=");
String k = kv;
String v = "";
if (i >= 0 && i < kv.length() - 1) {
k = kv.substring(0, i);
v = kv.substring(i + 1);
}
parameters.put(k, v);
}
}
}
restRequest.setParameters(parameters);
return restRequest;
}

Expand Down
2 changes: 1 addition & 1 deletion masker-rest-jjwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.github.jiashunx</groupId>
<artifactId>masker-rest</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.2.2.RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>masker-rest-jjwt</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion masker-rest-rsa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.github.jiashunx</groupId>
<artifactId>masker-rest</artifactId>
<version>2.2.1.RELEASE</version>
<version>2.2.2.RELEASE</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>masker-rest-rsa</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>masker-rest</artifactId>
<name>masker-rest</name>
<packaging>pom</packaging>
<version>2.2.1.RELEASE</version>
<version>2.2.2.RELEASE</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -156,6 +156,7 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
Expand Down

0 comments on commit 900cf94

Please sign in to comment.