1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -172,11 +172,11 @@ public void setCharacterEncoding(String characterEncoding) {
172
172
173
173
private void updateContentTypeHeader () {
174
174
if (this .contentType != null ) {
175
- StringBuilder sb = new StringBuilder ( this .contentType ) ;
176
- if (!this .contentType .toLowerCase ().contains (CHARSET_PREFIX ) && this . charset ) {
177
- sb . append ( ";" ). append ( CHARSET_PREFIX ). append ( this .characterEncoding ) ;
175
+ String value = this .contentType ;
176
+ if (this . charset && !this .contentType .toLowerCase ().contains (CHARSET_PREFIX )) {
177
+ value = value + ';' + CHARSET_PREFIX + this .characterEncoding ;
178
178
}
179
- doAddHeaderValue (HttpHeaders .CONTENT_TYPE , sb . toString () , true );
179
+ doAddHeaderValue (HttpHeaders .CONTENT_TYPE , value , true );
180
180
}
181
181
}
182
182
@@ -197,7 +197,8 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
197
197
Assert .state (this .writerAccessAllowed , "Writer access not allowed" );
198
198
if (this .writer == null ) {
199
199
Writer targetWriter = (this .characterEncoding != null ?
200
- new OutputStreamWriter (this .content , this .characterEncoding ) : new OutputStreamWriter (this .content ));
200
+ new OutputStreamWriter (this .content , this .characterEncoding ) :
201
+ new OutputStreamWriter (this .content ));
201
202
this .writer = new ResponsePrintWriter (targetWriter );
202
203
}
203
204
return this .writer ;
@@ -302,6 +303,7 @@ public boolean isCommitted() {
302
303
public void reset () {
303
304
resetBuffer ();
304
305
this .characterEncoding = null ;
306
+ this .charset = false ;
305
307
this .contentLength = 0 ;
306
308
this .contentType = null ;
307
309
this .locale = Locale .getDefault ();
@@ -395,7 +397,7 @@ public boolean containsHeader(String name) {
395
397
396
398
/**
397
399
* Return the names of all specified headers as a Set of Strings.
398
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
400
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
399
401
* @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
400
402
*/
401
403
@ Override
@@ -406,7 +408,7 @@ public Collection<String> getHeaderNames() {
406
408
/**
407
409
* Return the primary value for the given header as a String, if any.
408
410
* Will return the first value in case of multiple values.
409
- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
411
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
410
412
* As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
411
413
* Consider using {@link #getHeaderValue(String)} for raw Object access.
412
414
* @param name the name of the header
@@ -421,7 +423,7 @@ public String getHeader(String name) {
421
423
422
424
/**
423
425
* Return all values for the given header as a List of Strings.
424
- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
426
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
425
427
* As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
426
428
* Consider using {@link #getHeaderValues(String)} for raw Object access.
427
429
* @param name the name of the header
0 commit comments