File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
spring-web/src/main/java/org/springframework/http/server Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 27
27
28
28
import org .springframework .http .HttpHeaders ;
29
29
import org .springframework .http .HttpStatusCode ;
30
+ import org .springframework .http .MediaType ;
30
31
import org .springframework .lang .Nullable ;
31
32
import org .springframework .util .Assert ;
32
33
import org .springframework .util .CollectionUtils ;
@@ -118,12 +119,13 @@ private void writeHeaders() {
118
119
}
119
120
});
120
121
// HttpServletResponse exposes some headers as properties: we should include those if not already present
121
- if (this .servletResponse .getContentType () == null && this .headers .getContentType () != null ) {
122
- this .servletResponse .setContentType (this .headers .getContentType ().toString ());
122
+ MediaType contentTypeHeader = this .headers .getContentType ();
123
+ if (this .servletResponse .getContentType () == null && contentTypeHeader != null ) {
124
+ this .servletResponse .setContentType (contentTypeHeader .toString ());
123
125
}
124
- if (this .servletResponse .getCharacterEncoding () == null && this . headers . getContentType () != null &&
125
- this . headers . getContentType () .getCharset () != null ) {
126
- this .servletResponse .setCharacterEncoding (this . headers . getContentType () .getCharset ().name ());
126
+ if (this .servletResponse .getCharacterEncoding () == null && contentTypeHeader != null &&
127
+ contentTypeHeader .getCharset () != null ) {
128
+ this .servletResponse .setCharacterEncoding (contentTypeHeader .getCharset ().name ());
127
129
}
128
130
long contentLength = getHeaders ().getContentLength ();
129
131
if (contentLength != -1 ) {
You can’t perform that action at this time.
0 commit comments