1
1
/*
2
- * Copyright 2002-2017 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 (CONTENT_TYPE_HEADER , sb . toString () , true );
174
+ doAddHeaderValue (CONTENT_TYPE_HEADER , value , true );
175
175
}
176
176
}
177
177
@@ -195,7 +195,8 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
195
195
}
196
196
if (this .writer == null ) {
197
197
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 ));
199
200
this .writer = new ResponsePrintWriter (targetWriter );
200
201
}
201
202
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 = null ;
@@ -353,7 +355,7 @@ public boolean containsHeader(String name) {
353
355
354
356
/**
355
357
* 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} .
357
359
* @return the {@code Set} of header name {@code Strings}, or an empty {@code Set} if none
358
360
*/
359
361
@ Override
@@ -364,7 +366,7 @@ public Collection<String> getHeaderNames() {
364
366
/**
365
367
* Return the primary value for the given header as a String, if any.
366
368
* 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} .
368
370
* As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
369
371
* Consider using {@link #getHeaderValue(String)} for raw Object access.
370
372
* @param name the name of the header
@@ -378,7 +380,7 @@ public String getHeader(String name) {
378
380
379
381
/**
380
382
* 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} .
382
384
* As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
383
385
* Consider using {@link #getHeaderValues(String)} for raw Object access.
384
386
* @param name the name of the header
0 commit comments