From 70d33eab5dd849ed9ae57df8711312ee79fcd21c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 30 Mar 2017 11:20:39 +1100 Subject: [PATCH] Fixes #1435 --- .../org/eclipse/jetty/server/Response.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 0502955eb92..a0556a9d30d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -119,6 +119,7 @@ public class Response implements HttpServletResponse private enum EncodingFrom { NOT_SET, INFERRED, SET_LOCALE, SET_CONTENT_TYPE, SET_CHARACTER_ENCODING }; private static final EnumSet __localeOverride = EnumSet.of(EncodingFrom.NOT_SET,EncodingFrom.INFERRED); + private static final EnumSet __explicitCharset = EnumSet.of(EncodingFrom.SET_LOCALE,EncodingFrom.SET_CHARACTER_ENCODING); public Response(HttpChannel channel, HttpOutput out) @@ -1425,10 +1426,19 @@ public class Response implements HttpServletResponse HttpField ct=content.getContentType(); if (ct!=null) { - _fields.put(ct); - _contentType=ct.getValue(); - _characterEncoding=content.getCharacterEncoding(); - _mimeType=content.getMimeType(); + if (_characterEncoding!=null && + content.getCharacterEncoding()==null && + __explicitCharset.contains(_encodingFrom)) + { + setContentType(content.getMimeType().getBaseType().asString()); + } + else + { + _fields.put(ct); + _contentType=ct.getValue(); + _characterEncoding=content.getCharacterEncoding(); + _mimeType=content.getMimeType(); + } } HttpField ce=content.getContentEncoding();