Skip to content

Commit

Permalink
Issue #4719 incorporate new tests, fix char encoding that should be a…
Browse files Browse the repository at this point in the history
…ssumed

Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Mar 27, 2020
1 parent fc74c1e commit 775ad5a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,9 @@ public void setContentType(String contentType)
_contentType = contentType;
_mimeType = MimeTypes.CACHE.get(contentType);

String charset;
if (_mimeType != null && _mimeType.getCharset() != null && !_mimeType.isCharsetAssumed())
String charset = MimeTypes.getCharsetFromContentType(contentType);
if (charset == null && _mimeType != null && _mimeType.isCharsetAssumed())
charset = _mimeType.getCharsetString();
else
charset = MimeTypes.getCharsetFromContentType(contentType);

if (charset == null)
{
Expand Down Expand Up @@ -1056,10 +1054,10 @@ public void setContentType(String contentType)
else if (isWriting() && !charset.equalsIgnoreCase(_characterEncoding))
{
// too late to change the character encoding;
_mimeType = null;
_contentType = MimeTypes.getContentTypeWithoutCharset(_contentType);
if (_characterEncoding != null)
if (_characterEncoding != null && (_mimeType == null || !_mimeType.isCharsetAssumed()))
_contentType = _contentType + ";charset=" + _characterEncoding;
_mimeType = MimeTypes.CACHE.get(_contentType);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void testCharsetChangeToJsonMimeTypeSetCharsetToNull() throws Exception
{
HttpTester.Request request = new HttpTester.Request();
request.setMethod("GET");
request.setURI("/charset/json-reset-null/");
request.setURI("/charset/json-change-null/");
request.setVersion(HttpVersion.HTTP_1_1);
request.setHeader("Connection", "close");
request.setHeader("Host", "test");
Expand Down

0 comments on commit 775ad5a

Please sign in to comment.