Skip to content

Commit

Permalink
bugfix: 修复两个RequestWrapper类的头信息多次获取导致丢失的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Dec 26, 2023
1 parent 0899f2f commit 7aeb6d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
*/
public class ApplicationJsonHttpServletRequestWrapper extends BodyHttpServletRequestWrapper {

private final static Enumeration<String> CONTENT_TYPE_ENUMERATION = Collections.enumeration(Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));


public ApplicationJsonHttpServletRequestWrapper(HttpServletRequest request, String jsonData) {
super(request, jsonData);
}
Expand All @@ -55,7 +52,7 @@ public String getHeader(String name) {
@Override
public Enumeration<String> getHeaders(String name) {
if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) {
return CONTENT_TYPE_ENUMERATION;
return Collections.enumeration(Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
}

return super.getHeaders(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class BodyHttpServletRequestWrapper extends HttpServletRequestWrapper {


private final int contentLength;
private final Enumeration<String> contentLengthEnumeration;

@Nonnull
private ServletInputStream inputStream;
Expand All @@ -66,7 +65,6 @@ public BodyHttpServletRequestWrapper(HttpServletRequest request, String body) {
byte[] bodyBytes = body.getBytes(DEFAULT_CHARSET);

this.contentLength = bodyBytes.length;
this.contentLengthEnumeration = Collections.enumeration(Collections.singletonList(String.valueOf(contentLength)));
this.inputStream = new BodyServletInputStream(bodyBytes);
}

Expand Down Expand Up @@ -124,7 +122,7 @@ public int getIntHeader(String name) {
@Override
public Enumeration<String> getHeaders(String name) {
if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) {
return contentLengthEnumeration;
return Collections.enumeration(Collections.singletonList(String.valueOf(this.contentLength)));
}

return super.getHeaders(name);
Expand Down

0 comments on commit 7aeb6d1

Please sign in to comment.