Add formData() and multipartData() to ServerRequest

Issue: SPR-16551
This commit is contained in:
Arjen Poutsma
2018-03-23 09:58:59 +01:00
parent 1b83f129a2
commit c56317928f
7 changed files with 160 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -39,6 +39,7 @@ import org.springframework.http.HttpRange;
import org.springframework.http.HttpRequest;
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.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
@@ -190,6 +191,16 @@ class DefaultServerRequest implements ServerRequest {
return this.exchange.getPrincipal();
}
@Override
public Mono<MultiValueMap<String, String>> formData() {
return this.exchange.getFormData();
}
@Override
public Mono<MultiValueMap<String, Part>> multipartData() {
return this.exchange.getMultipartData();
}
private ServerHttpRequest request() {
return this.exchange.getRequest();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -39,6 +39,7 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.lang.Nullable;
@@ -582,6 +583,16 @@ public abstract class RequestPredicates {
return this.request.principal();
}
@Override
public Mono<MultiValueMap<String, String>> formData() {
return this.request.formData();
}
@Override
public Mono<MultiValueMap<String, Part>> multipartData() {
return this.request.multipartData();
}
@Override
public String toString() {
return method() + " " + path();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -37,6 +37,7 @@ import org.springframework.http.HttpRange;
import org.springframework.http.MediaType;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.http.codec.json.Jackson2CodecSupport;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.lang.Nullable;
@@ -244,6 +245,27 @@ public interface ServerRequest {
*/
Mono<? extends Principal> principal();
/**
* Return the form data from the body of the request if the Content-Type is
* {@code "application/x-www-form-urlencoded"} or an empty map otherwise.
*
* <p><strong>Note:</strong> calling this method causes the request body to
* be read and parsed in full and the resulting {@code MultiValueMap} is
* cached so that this method is safe to call more than once.
*/
Mono<MultiValueMap<String, String>> formData();
/**
* Return the parts of a multipart request if the Content-Type is
* {@code "multipart/form-data"} or an empty map otherwise.
*
* <p><strong>Note:</strong> calling this method causes the request body to
* be read and parsed in full and the resulting {@code MultiValueMap} is
* cached so that this method is safe to call more than once.
*/
Mono<MultiValueMap<String, Part>> multipartData();
/**
* Create a new {@code ServerRequest} based on the given {@code ServerWebExchange} and

View File

@@ -35,6 +35,7 @@ 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.multipart.Part;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.Assert;
@@ -185,6 +186,16 @@ public class ServerRequestWrapper implements ServerRequest {
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();
}
/**
* Implementation of the {@code Headers} interface that can be subclassed
* to adapt the headers in a