48
48
import org .springframework .web .server .WebSession ;
49
49
import org .springframework .web .server .session .WebSessionManager ;
50
50
51
- import static org .springframework .http .MediaType .APPLICATION_FORM_URLENCODED ;
52
- import static org .springframework .http .MediaType .MULTIPART_FORM_DATA ;
53
-
54
51
/**
55
52
* Default implementation of {@link ServerWebExchange}.
56
53
*
@@ -61,10 +58,10 @@ public class DefaultServerWebExchange implements ServerWebExchange {
61
58
62
59
private static final List <HttpMethod > SAFE_METHODS = Arrays .asList (HttpMethod .GET , HttpMethod .HEAD );
63
60
64
- private static final ResolvableType FORM_DATA_VALUE_TYPE =
61
+ private static final ResolvableType FORM_DATA_TYPE =
65
62
ResolvableType .forClassWithGenerics (MultiValueMap .class , String .class , String .class );
66
63
67
- private static final ResolvableType MULTIPART_VALUE_TYPE = ResolvableType .forClassWithGenerics (
64
+ private static final ResolvableType MULTIPART_DATA_TYPE = ResolvableType .forClassWithGenerics (
68
65
MultiValueMap .class , String .class , Part .class );
69
66
70
67
private static final Mono <MultiValueMap <String , String >> EMPTY_FORM_DATA =
@@ -110,21 +107,17 @@ public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse re
110
107
}
111
108
112
109
@ SuppressWarnings ("unchecked" )
113
- private static Mono <MultiValueMap <String , String >> initFormData (
114
- ServerHttpRequest request , ServerCodecConfigurer codecConfigurer ) {
110
+ private static Mono <MultiValueMap <String , String >> initFormData (ServerHttpRequest request ,
111
+ ServerCodecConfigurer configurer ) {
115
112
116
- MediaType contentType ;
117
113
try {
118
- contentType = request .getHeaders ().getContentType ();
119
- if (APPLICATION_FORM_URLENCODED .isCompatibleWith (contentType )) {
120
- return ((HttpMessageReader <MultiValueMap <String , String >>)codecConfigurer
121
- .getReaders ()
122
- .stream ()
123
- .filter (reader -> reader .canRead (FORM_DATA_VALUE_TYPE , APPLICATION_FORM_URLENCODED ))
114
+ MediaType contentType = request .getHeaders ().getContentType ();
115
+ if (MediaType .APPLICATION_FORM_URLENCODED .isCompatibleWith (contentType )) {
116
+ return ((HttpMessageReader <MultiValueMap <String , String >>) configurer .getReaders ().stream ()
117
+ .filter (reader -> reader .canRead (FORM_DATA_TYPE , MediaType .APPLICATION_FORM_URLENCODED ))
124
118
.findFirst ()
125
- .orElseThrow (() -> new IllegalStateException (
126
- "Could not find HttpMessageReader that supports " + APPLICATION_FORM_URLENCODED )))
127
- .readMono (FORM_DATA_VALUE_TYPE , request , Collections .emptyMap ())
119
+ .orElseThrow (() -> new IllegalStateException ("No form data HttpMessageReader." )))
120
+ .readMono (FORM_DATA_TYPE , request , Collections .emptyMap ())
128
121
.switchIfEmpty (EMPTY_FORM_DATA )
129
122
.cache ();
130
123
}
@@ -136,21 +129,17 @@ private static Mono<MultiValueMap<String, String>> initFormData(
136
129
}
137
130
138
131
@ SuppressWarnings ("unchecked" )
139
- private static Mono <MultiValueMap <String , Part >> initMultipartData (
140
- ServerHttpRequest request , ServerCodecConfigurer codecConfigurer ) {
132
+ private static Mono <MultiValueMap <String , Part >> initMultipartData (ServerHttpRequest request ,
133
+ ServerCodecConfigurer configurer ) {
141
134
142
- MediaType contentType ;
143
135
try {
144
- contentType = request .getHeaders ().getContentType ();
145
- if (MULTIPART_FORM_DATA .isCompatibleWith (contentType )) {
146
- return ((HttpMessageReader <MultiValueMap <String , Part >>) codecConfigurer
147
- .getReaders ()
148
- .stream ()
149
- .filter (reader -> reader .canRead (MULTIPART_VALUE_TYPE , MULTIPART_FORM_DATA ))
136
+ MediaType contentType = request .getHeaders ().getContentType ();
137
+ if (MediaType .MULTIPART_FORM_DATA .isCompatibleWith (contentType )) {
138
+ return ((HttpMessageReader <MultiValueMap <String , Part >>) configurer .getReaders ().stream ()
139
+ .filter (reader -> reader .canRead (MULTIPART_DATA_TYPE , MediaType .MULTIPART_FORM_DATA ))
150
140
.findFirst ()
151
- .orElseThrow (() -> new IllegalStateException (
152
- "Could not find HttpMessageReader that supports " + MULTIPART_FORM_DATA )))
153
- .readMono (FORM_DATA_VALUE_TYPE , request , Collections .emptyMap ())
141
+ .orElseThrow (() -> new IllegalStateException ("No multipart HttpMessageReader." )))
142
+ .readMono (MULTIPART_DATA_TYPE , request , Collections .emptyMap ())
154
143
.switchIfEmpty (EMPTY_MULTIPART_DATA )
155
144
.cache ();
156
145
}
0 commit comments