|
|
|
@ -67,37 +67,39 @@ import org.springframework.web.util.UriUtils; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
|
|
|
|
|
|
|
|
private final HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Object> attributes = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<HttpMessageReader<?>> messageReaders; |
|
|
|
private final List<HttpMessageReader<?>> messageReaders; |
|
|
|
|
|
|
|
|
|
|
|
private ServerWebExchange exchange; |
|
|
|
private ServerWebExchange exchange; |
|
|
|
|
|
|
|
|
|
|
|
private HttpMethod method = HttpMethod.GET; |
|
|
|
private String methodName; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
private URI uri; |
|
|
|
private URI uri; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Object> attributes = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
private Flux<DataBuffer> body = Flux.empty(); |
|
|
|
private Flux<DataBuffer> body = Flux.empty(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DefaultServerRequestBuilder(ServerRequest other) { |
|
|
|
public DefaultServerRequestBuilder(ServerRequest other) { |
|
|
|
Assert.notNull(other, "ServerRequest must not be null"); |
|
|
|
Assert.notNull(other, "ServerRequest must not be null"); |
|
|
|
this.messageReaders = other.messageReaders(); |
|
|
|
this.messageReaders = other.messageReaders(); |
|
|
|
this.exchange = other.exchange(); |
|
|
|
this.exchange = other.exchange(); |
|
|
|
method(other.method()); |
|
|
|
this.methodName = other.methodName(); |
|
|
|
uri(other.uri()); |
|
|
|
this.uri = other.uri(); |
|
|
|
headers(headers -> headers.addAll(other.headers().asHttpHeaders())); |
|
|
|
headers(headers -> headers.addAll(other.headers().asHttpHeaders())); |
|
|
|
cookies(cookies -> cookies.addAll(other.cookies())); |
|
|
|
cookies(cookies -> cookies.addAll(other.cookies())); |
|
|
|
|
|
|
|
attributes(attributes -> attributes.putAll(other.attributes())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ServerRequest.Builder method(HttpMethod method) { |
|
|
|
public ServerRequest.Builder method(HttpMethod method) { |
|
|
|
Assert.notNull(method, "'method' must not be null"); |
|
|
|
Assert.notNull(method, "'method' must not be null"); |
|
|
|
this.method = method; |
|
|
|
this.methodName = method.name(); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +120,6 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ServerRequest.Builder headers(Consumer<HttpHeaders> headersConsumer) { |
|
|
|
public ServerRequest.Builder headers(Consumer<HttpHeaders> headersConsumer) { |
|
|
|
Assert.notNull(headersConsumer, "'headersConsumer' must not be null"); |
|
|
|
|
|
|
|
headersConsumer.accept(this.headers); |
|
|
|
headersConsumer.accept(this.headers); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -132,10 +133,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ServerRequest.Builder cookies( |
|
|
|
public ServerRequest.Builder cookies(Consumer<MultiValueMap<String, HttpCookie>> cookiesConsumer) { |
|
|
|
Consumer<MultiValueMap<String, HttpCookie>> cookiesConsumer) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(cookiesConsumer, "'cookiesConsumer' must not be null"); |
|
|
|
|
|
|
|
cookiesConsumer.accept(this.cookies); |
|
|
|
cookiesConsumer.accept(this.cookies); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -174,26 +172,25 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ServerRequest.Builder attributes(Consumer<Map<String, Object>> attributesConsumer) { |
|
|
|
public ServerRequest.Builder attributes(Consumer<Map<String, Object>> attributesConsumer) { |
|
|
|
Assert.notNull(attributesConsumer, "'attributesConsumer' must not be null"); |
|
|
|
|
|
|
|
attributesConsumer.accept(this.attributes); |
|
|
|
attributesConsumer.accept(this.attributes); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ServerRequest build() { |
|
|
|
public ServerRequest build() { |
|
|
|
ServerHttpRequest serverHttpRequest = new BuiltServerHttpRequest(this.method, this.uri, |
|
|
|
ServerHttpRequest serverHttpRequest = new BuiltServerHttpRequest( |
|
|
|
this.headers, this.cookies, this.body); |
|
|
|
this.methodName, this.uri, this.headers, this.cookies, this.body); |
|
|
|
ServerWebExchange exchange = new DelegatingServerWebExchange(serverHttpRequest, |
|
|
|
ServerWebExchange exchange = new DelegatingServerWebExchange( |
|
|
|
this.exchange, this.messageReaders); |
|
|
|
serverHttpRequest, this.exchange, this.messageReaders); |
|
|
|
return new DefaultServerRequest(exchange, this.messageReaders); |
|
|
|
return new DefaultServerRequest(exchange, this.messageReaders); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class BuiltServerHttpRequest implements ServerHttpRequest { |
|
|
|
private static class BuiltServerHttpRequest implements ServerHttpRequest { |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern QUERY_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?"); |
|
|
|
private static final Pattern QUERY_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String method; |
|
|
|
private final HttpMethod method; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final URI uri; |
|
|
|
private final URI uri; |
|
|
|
|
|
|
|
|
|
|
|
@ -207,10 +204,9 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
|
|
|
|
|
|
|
|
private final Flux<DataBuffer> body; |
|
|
|
private final Flux<DataBuffer> body; |
|
|
|
|
|
|
|
|
|
|
|
public BuiltServerHttpRequest(HttpMethod method, URI uri, |
|
|
|
public BuiltServerHttpRequest(String method, URI uri, HttpHeaders headers, |
|
|
|
HttpHeaders headers, |
|
|
|
MultiValueMap<String, HttpCookie> cookies, Flux<DataBuffer> body) { |
|
|
|
MultiValueMap<String, HttpCookie> cookies, |
|
|
|
|
|
|
|
Flux<DataBuffer> body) { |
|
|
|
|
|
|
|
this.method = method; |
|
|
|
this.method = method; |
|
|
|
this.uri = uri; |
|
|
|
this.uri = uri; |
|
|
|
this.path = RequestPath.parse(uri, null); |
|
|
|
this.path = RequestPath.parse(uri, null); |
|
|
|
@ -245,15 +241,9 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
return queryParams; |
|
|
|
return queryParams; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public HttpMethod getMethod() { |
|
|
|
|
|
|
|
return this.method; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getMethodValue() { |
|
|
|
public String getMethodValue() { |
|
|
|
return this.method.name(); |
|
|
|
return this.method; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -287,6 +277,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class DelegatingServerWebExchange implements ServerWebExchange { |
|
|
|
private static class DelegatingServerWebExchange implements ServerWebExchange { |
|
|
|
|
|
|
|
|
|
|
|
private static final ResolvableType FORM_DATA_TYPE = |
|
|
|
private static final ResolvableType FORM_DATA_TYPE = |
|
|
|
@ -296,12 +287,10 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
MultiValueMap.class, String.class, Part.class); |
|
|
|
MultiValueMap.class, String.class, Part.class); |
|
|
|
|
|
|
|
|
|
|
|
private static final Mono<MultiValueMap<String, String>> EMPTY_FORM_DATA = |
|
|
|
private static final Mono<MultiValueMap<String, String>> EMPTY_FORM_DATA = |
|
|
|
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0))) |
|
|
|
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0))).cache(); |
|
|
|
.cache(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Mono<MultiValueMap<String, Part>> EMPTY_MULTIPART_DATA = |
|
|
|
private static final Mono<MultiValueMap<String, Part>> EMPTY_MULTIPART_DATA = |
|
|
|
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, Part>(0))) |
|
|
|
Mono.just(CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, Part>(0))).cache(); |
|
|
|
.cache(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ServerHttpRequest request; |
|
|
|
private final ServerHttpRequest request; |
|
|
|
|
|
|
|
|
|
|
|
@ -311,8 +300,9 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
|
|
|
|
|
|
|
|
private final Mono<MultiValueMap<String, Part>> multipartDataMono; |
|
|
|
private final Mono<MultiValueMap<String, Part>> multipartDataMono; |
|
|
|
|
|
|
|
|
|
|
|
public DelegatingServerWebExchange(ServerHttpRequest request, ServerWebExchange delegate, |
|
|
|
public DelegatingServerWebExchange( |
|
|
|
List<HttpMessageReader<?>> messageReaders) { |
|
|
|
ServerHttpRequest request, ServerWebExchange delegate, List<HttpMessageReader<?>> messageReaders) { |
|
|
|
|
|
|
|
|
|
|
|
this.request = request; |
|
|
|
this.request = request; |
|
|
|
this.delegate = delegate; |
|
|
|
this.delegate = delegate; |
|
|
|
this.formDataMono = initFormData(request, messageReaders); |
|
|
|
this.formDataMono = initFormData(request, messageReaders); |
|
|
|
@ -399,7 +389,6 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { |
|
|
|
return this.delegate.getPrincipal(); |
|
|
|
return this.delegate.getPrincipal(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public LocaleContext getLocaleContext() { |
|
|
|
public LocaleContext getLocaleContext() { |
|
|
|
return this.delegate.getLocaleContext(); |
|
|
|
return this.delegate.getLocaleContext(); |
|
|
|
|