File tree Expand file tree Collapse file tree 4 files changed +35
-5
lines changed
spring-web/src/main/java/org/springframework/http/server/reactive Expand file tree Collapse file tree 4 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -262,8 +262,13 @@ protected Mono<Void> doCommit(@Nullable Supplier<? extends Mono<Void>> writeActi
262
262
protected abstract void applyStatusCode ();
263
263
264
264
/**
265
- * Apply header changes from {@link #getHeaders()} to the underlying response.
266
- * This method is called once only.
265
+ * Invoked when the response is getting committed allowing sub-classes to
266
+ * make apply header values to the underlying response.
267
+ * <p>Note that most sub-classes use an {@link HttpHeaders} instance that
268
+ * wraps an adapter to the native response headers such that changes are
269
+ * propagated to the underlying response on the go. That means this callback
270
+ * is typically not used other than for specialized updates such as setting
271
+ * the contentType or characterEncoding fields in a Servlet response.
267
272
*/
268
273
protected abstract void applyHeaders ();
269
274
Original file line number Diff line number Diff line change @@ -101,8 +101,15 @@ private static HttpHeaders createHeaders(HttpServletResponse response) {
101
101
102
102
@ Override
103
103
protected void applyHeaders () {
104
- MediaType contentType = getHeaders ().getContentType ();
105
104
HttpServletResponse response = getNativeResponse ();
105
+ MediaType contentType = null ;
106
+ try {
107
+ contentType = getHeaders ().getContentType ();
108
+ }
109
+ catch (Exception ex ) {
110
+ String rawContentType = getHeaders ().getFirst (HttpHeaders .CONTENT_TYPE );
111
+ response .setContentType (rawContentType );
112
+ }
106
113
if (response .getContentType () == null && contentType != null ) {
107
114
response .setContentType (contentType .toString ());
108
115
}
Original file line number Diff line number Diff line change @@ -118,14 +118,25 @@ protected void applyHeaders() {
118
118
this .response .addHeader (headerName , headerValue );
119
119
}
120
120
});
121
- MediaType contentType = getHeaders ().getContentType ();
121
+ MediaType contentType = null ;
122
+ try {
123
+ contentType = getHeaders ().getContentType ();
124
+ }
125
+ catch (Exception ex ) {
126
+ String rawContentType = getHeaders ().getFirst (HttpHeaders .CONTENT_TYPE );
127
+ this .response .setContentType (rawContentType );
128
+ }
122
129
if (this .response .getContentType () == null && contentType != null ) {
123
130
this .response .setContentType (contentType .toString ());
124
131
}
125
132
Charset charset = (contentType != null ? contentType .getCharset () : null );
126
133
if (this .response .getCharacterEncoding () == null && charset != null ) {
127
134
this .response .setCharacterEncoding (charset .name ());
128
135
}
136
+ long contentLength = getHeaders ().getContentLength ();
137
+ if (contentLength != -1 ) {
138
+ this .response .setContentLengthLong (contentLength );
139
+ }
129
140
}
130
141
131
142
@ Override
Original file line number Diff line number Diff line change @@ -204,7 +204,14 @@ else if (response instanceof HttpServletResponseWrapper) {
204
204
@ Override
205
205
protected void applyHeaders () {
206
206
HttpServletResponse response = getNativeResponse ();
207
- MediaType contentType = getHeaders ().getContentType ();
207
+ MediaType contentType = null ;
208
+ try {
209
+ contentType = getHeaders ().getContentType ();
210
+ }
211
+ catch (Exception ex ) {
212
+ String rawContentType = getHeaders ().getFirst (HttpHeaders .CONTENT_TYPE );
213
+ response .setContentType (rawContentType );
214
+ }
208
215
if (response .getContentType () == null && contentType != null ) {
209
216
response .setContentType (contentType .toString ());
210
217
}
You can’t perform that action at this time.
0 commit comments