Skip to content

Commit

Permalink
[bug] Get request parameter issue close(#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava committed Feb 28, 2024
1 parent 6e13e6d commit a5d75de
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void callMethod(MvcContext context, MvcRequest request, MvcResponse respo
Safe.run(() -> {
Object[] params = new Object[]{null};
//If there is only one parameter and it is a String, no further parsing is necessary; it can be used directly.
if (isSingleStringParameterMethod(method)) {
if (isSingleStringParameterMethod(method) && request.getMethod().toUpperCase().equals("POST")) {
params[0] = new String(request.getBody());
} else {
JsonElement args = getArgs(method, request.getMethod().toLowerCase(Locale.ROOT), request, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class MvcContext {

private Object response;

private String contentType;

/**
* rate limited or exceeded quota
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void writeAndFlush(MvcContext context, HttpResponseStatus status, String
} else {
FullHttpResponse response = HttpResponseUtils.create(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, Unpooled.wrappedBuffer(message.getBytes())));
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, message.getBytes().length);
if (StringUtils.isNotEmpty(context.getContentType())) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, context.getContentType());
}
context.getResHeaders().forEach((k, v) -> response.headers().set(k, v));
if (context.isAllowCross()) {
response.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
Expand All @@ -53,7 +56,7 @@ public void writeAndFlush(MvcContext context, HttpResponseStatus status, String
HttpSessionManager.setSessionId(context, HttpSessionManager.isHasSessionId(context.getHeaders()), response);
}
if (StringUtils.isNotEmpty(context.getRequest().headers().get(HttpHeaderNames.CONNECTION))) {
response.headers().add(HttpHeaderNames.CONNECTION,context.getRequest().headers().get(HttpHeaderNames.CONNECTION));
response.headers().add(HttpHeaderNames.CONNECTION, context.getRequest().headers().get(HttpHeaderNames.CONNECTION));
}
ctx.writeAndFlush(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void run() {

private void call() {
if (context.isWebsocket()) {
WsRequest req = new Gson().fromJson(new String(request.getBody()), WsRequest.class);
WsRequest req = GsonUtils.gson.fromJson(new String(request.getBody()), WsRequest.class);
request.setPath(req.getPath());
request.setBody(GsonUtils.gson.toJson(req.getParams()).getBytes());
}
Expand All @@ -122,6 +122,9 @@ private void call() {
sendNotFoundResponse();
return;
}
if(path.endsWith(".html")) {
context.setContentType("text/html; charset=utf-8");
}
response.writeAndFlush(context, content);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ public String testGet(@RequestParam("a") int a, @RequestParam("b") int b) {
return String.valueOf(a + b);
}

@TAnno
@RequestMapping(path = "/testv", method = "get")
public String testV(@RequestParam("a") String a) {
return a;
}

@RequestMapping(path = "/testpost")
public String testPost(String b) {
log.info("b={}", b);
Expand Down

0 comments on commit a5d75de

Please sign in to comment.