/
ServerRequestWrapper.java
293 lines (241 loc) · 7.15 KB
/
ServerRequestWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.Principal;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebSession;
import org.springframework.web.util.UriBuilder;
/**
* Implementation of the {@link ServerRequest} interface that can be subclassed
* to adapt the request in a
* {@link org.springframework.web.reactive.function.server.HandlerFilterFunction handler filter function}.
* All methods default to calling through to the wrapped request.
*
* @author Arjen Poutsma
* @since 5.0
*/
public class ServerRequestWrapper implements ServerRequest {
private final ServerRequest delegate;
/**
* Create a new {@code ServerRequestWrapper} that wraps the given request.
* @param delegate the request to wrap
*/
public ServerRequestWrapper(ServerRequest delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate;
}
/**
* Return the wrapped request.
*/
public ServerRequest request() {
return this.delegate;
}
@Override
public HttpMethod method() {
return this.delegate.method();
}
@Override
public String methodName() {
return this.delegate.methodName();
}
@Override
public URI uri() {
return this.delegate.uri();
}
@Override
public UriBuilder uriBuilder() {
return this.delegate.uriBuilder();
}
@Override
public String path() {
return this.delegate.path();
}
@Override
@Deprecated
public PathContainer pathContainer() {
return this.delegate.pathContainer();
}
@Override
public RequestPath requestPath() {
return this.delegate.requestPath();
}
@Override
public Headers headers() {
return this.delegate.headers();
}
@Override
public MultiValueMap<String, HttpCookie> cookies() {
return this.delegate.cookies();
}
@Override
public Optional<InetSocketAddress> remoteAddress() {
return this.delegate.remoteAddress();
}
@Override
public Optional<InetSocketAddress> localAddress() {
return this.delegate.localAddress();
}
@Override
public List<HttpMessageReader<?>> messageReaders() {
return this.delegate.messageReaders();
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor) {
return this.delegate.body(extractor);
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor, Map<String, Object> hints) {
return this.delegate.body(extractor, hints);
}
@Override
public <T> Mono<T> bodyToMono(Class<? extends T> elementClass) {
return this.delegate.bodyToMono(elementClass);
}
@Override
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference) {
return this.delegate.bodyToMono(typeReference);
}
@Override
public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass) {
return this.delegate.bodyToFlux(elementClass);
}
@Override
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
return this.delegate.bodyToFlux(typeReference);
}
@Override
public Optional<Object> attribute(String name) {
return this.delegate.attribute(name);
}
@Override
public Map<String, Object> attributes() {
return this.delegate.attributes();
}
@Override
public Optional<String> queryParam(String name) {
return this.delegate.queryParam(name);
}
@Override
public MultiValueMap<String, String> queryParams() {
return this.delegate.queryParams();
}
@Override
public String pathVariable(String name) {
return this.delegate.pathVariable(name);
}
@Override
public Map<String, String> pathVariables() {
return this.delegate.pathVariables();
}
@Override
public Mono<WebSession> session() {
return this.delegate.session();
}
@Override
public Mono<? extends Principal> principal() {
return this.delegate.principal();
}
@Override
public Mono<MultiValueMap<String, String>> formData() {
return this.delegate.formData();
}
@Override
public Mono<MultiValueMap<String, Part>> multipartData() {
return this.delegate.multipartData();
}
@Override
public ServerWebExchange exchange() {
return this.delegate.exchange();
}
/**
* Implementation of the {@code Headers} interface that can be subclassed
* to adapt the headers in a
* {@link org.springframework.web.reactive.function.server.HandlerFilterFunction handler filter function}.
* All methods default to calling through to the wrapped headers.
*/
public static class HeadersWrapper implements ServerRequest.Headers {
private final Headers headers;
/**
* Create a new {@code HeadersWrapper} that wraps the given request.
* @param headers the headers to wrap
*/
public HeadersWrapper(Headers headers) {
Assert.notNull(headers, "Headers must not be null");
this.headers = headers;
}
@Override
public List<MediaType> accept() {
return this.headers.accept();
}
@Override
public List<Charset> acceptCharset() {
return this.headers.acceptCharset();
}
@Override
public List<Locale.LanguageRange> acceptLanguage() {
return this.headers.acceptLanguage();
}
@Override
public OptionalLong contentLength() {
return this.headers.contentLength();
}
@Override
public Optional<MediaType> contentType() {
return this.headers.contentType();
}
@Override
public InetSocketAddress host() {
return this.headers.host();
}
@Override
public List<HttpRange> range() {
return this.headers.range();
}
@Override
public List<String> header(String headerName) {
return this.headers.header(headerName);
}
@Override
public HttpHeaders asHttpHeaders() {
return this.headers.asHttpHeaders();
}
}
}