11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2020 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -167,11 +167,11 @@ public void setCharacterEncoding(String characterEncoding) {
167167
168168 private void updateContentTypeHeader () {
169169 if (this .contentType != null ) {
170- StringBuilder sb = new StringBuilder ( this .contentType ) ;
171- if (!this .contentType .toLowerCase ().contains (CHARSET_PREFIX ) && this . charset ) {
172- sb . append ( ";" ). append ( CHARSET_PREFIX ). append ( this .characterEncoding ) ;
170+ String value = this .contentType ;
171+ if (this . charset && !this .contentType .toLowerCase ().contains (CHARSET_PREFIX )) {
172+ value = value + ';' + CHARSET_PREFIX + this .characterEncoding ;
173173 }
174- doAddHeaderValue (CONTENT_TYPE_HEADER , sb . toString () , true );
174+ doAddHeaderValue (CONTENT_TYPE_HEADER , value , true );
175175 }
176176 }
177177
@@ -195,7 +195,8 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
195195 }
196196 if (this .writer == null ) {
197197 Writer targetWriter = (this .characterEncoding != null ?
198- new OutputStreamWriter (this .content , this .characterEncoding ) : new OutputStreamWriter (this .content ));
198+ new OutputStreamWriter (this .content , this .characterEncoding ) :
199+ new OutputStreamWriter (this .content ));
199200 this .writer = new ResponsePrintWriter (targetWriter );
200201 }
201202 return this .writer ;
@@ -302,6 +303,7 @@ public boolean isCommitted() {
302303 public void reset () {
303304 resetBuffer ();
304305 this .characterEncoding = null ;
306+ this .charset = false ;
305307 this .contentLength = 0 ;
306308 this .contentType = null ;
307309 this .locale = null ;
@@ -353,7 +355,7 @@ public boolean containsHeader(String name) {
353355
354356 /**
355357 * Return the names of all specified headers as a Set of Strings.
356- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
358+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
357359 * @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
358360 */
359361 @ Override
@@ -364,7 +366,7 @@ public Collection<String> getHeaderNames() {
364366 /**
365367 * Return the primary value for the given header as a String, if any.
366368 * Will return the first value in case of multiple values.
367- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
369+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
368370 * As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
369371 * Consider using {@link #getHeaderValue(String)} for raw Object access.
370372 * @param name the name of the header
@@ -378,7 +380,7 @@ public String getHeader(String name) {
378380
379381 /**
380382 * Return all values for the given header as a List of Strings.
381- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
383+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
382384 * As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
383385 * Consider using {@link #getHeaderValues(String)} for raw Object access.
384386 * @param name the name of the header
0 commit comments