1
1
/*
2
- * Copyright 2002-2018 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.
@@ -167,11 +167,11 @@ public void setCharacterEncoding(String characterEncoding) {
167
167
168
168
private void updateContentTypeHeader () {
169
169
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 ;
173
173
}
174
- doAddHeaderValue (HttpHeaders .CONTENT_TYPE , sb . toString () , true );
174
+ doAddHeaderValue (HttpHeaders .CONTENT_TYPE , value , true );
175
175
}
176
176
}
177
177
@@ -192,7 +192,8 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
192
192
Assert .state (this .writerAccessAllowed , "Writer access not allowed" );
193
193
if (this .writer == null ) {
194
194
Writer targetWriter = (this .characterEncoding != null ?
195
- new OutputStreamWriter (this .content , this .characterEncoding ) : new OutputStreamWriter (this .content ));
195
+ new OutputStreamWriter (this .content , this .characterEncoding ) :
196
+ new OutputStreamWriter (this .content ));
196
197
this .writer = new ResponsePrintWriter (targetWriter );
197
198
}
198
199
return this .writer ;
@@ -297,6 +298,7 @@ public boolean isCommitted() {
297
298
public void reset () {
298
299
resetBuffer ();
299
300
this .characterEncoding = null ;
301
+ this .charset = false ;
300
302
this .contentLength = 0 ;
301
303
this .contentType = null ;
302
304
this .locale = Locale .getDefault ();
@@ -378,7 +380,7 @@ public boolean containsHeader(String name) {
378
380
379
381
/**
380
382
* Return the names of all specified headers as a Set of Strings.
381
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
383
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
382
384
* @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
383
385
*/
384
386
@ Override
@@ -389,7 +391,7 @@ public Collection<String> getHeaderNames() {
389
391
/**
390
392
* Return the primary value for the given header as a String, if any.
391
393
* Will return the first value in case of multiple values.
392
- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
394
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
393
395
* As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
394
396
* Consider using {@link #getHeaderValue(String)} for raw Object access.
395
397
* @param name the name of the header
@@ -404,7 +406,7 @@ public String getHeader(String name) {
404
406
405
407
/**
406
408
* Return all values for the given header as a List of Strings.
407
- * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
409
+ * <p>As of Servlet 3.0, this method is also defined in {@link HttpServletResponse} .
408
410
* As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
409
411
* Consider using {@link #getHeaderValues(String)} for raw Object access.
410
412
* @param name the name of the header
0 commit comments