Skip to content

Commit

Permalink
Fix MockHttpServletRequest.java
Browse files Browse the repository at this point in the history
In MockHttpServletRequest 'application/json; Modified so that the 'charset=utf-8' format is no longer used.
  • Loading branch information
cnabro committed Apr 27, 2024
1 parent a662f5e commit 4e6fffa
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ public void setCharacterEncoding(@Nullable String characterEncoding) {

private void updateContentTypeHeader() {
if (StringUtils.hasLength(this.contentType)) {
if (isJsonContentType(this.contentType) {
return;
}

String value = this.contentType;
if (StringUtils.hasLength(this.characterEncoding) && !this.contentType.toLowerCase().contains(CHARSET_PREFIX)) {
value += ';' + CHARSET_PREFIX + this.characterEncoding;
Expand All @@ -417,6 +421,10 @@ private void updateContentTypeHeader() {
}
}

private boolean isJsonContentType(String contentType) {
return contentType.toLowerCase().startsWith("application/json");
}

/**
* Set the content of the request body as a byte array.
* <p>If the supplied byte array represents text such as XML or JSON, the
Expand Down

0 comments on commit 4e6fffa

Please sign in to comment.