Add remoteAddress() to ServerRequest

Issue: SPR-16681
This commit is contained in:
Arjen Poutsma
2018-04-10 11:13:45 +02:00
parent ff53d78e96
commit 7e2726f400
6 changed files with 94 additions and 6 deletions

View File

@@ -116,6 +116,11 @@ class DefaultServerRequest implements ServerRequest {
return request().getCookies();
}
@Override
public Optional<InetSocketAddress> remoteAddress() {
return Optional.ofNullable(request().getRemoteAddress());
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor) {
return body(extractor, Collections.emptyMap());

View File

@@ -16,6 +16,7 @@
package org.springframework.web.reactive.function.server;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.Principal;
import java.util.ArrayList;
@@ -513,6 +514,11 @@ public abstract class RequestPredicates {
return this.request.cookies();
}
@Override
public Optional<InetSocketAddress> remoteAddress() {
return this.request.remoteAddress();
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor) {
return this.request.body(extractor);

View File

@@ -114,6 +114,12 @@ public interface ServerRequest {
*/
MultiValueMap<String, HttpCookie> cookies();
/**
* Return the remote address where this request is connected to, if available.
* @since 5.1
*/
Optional<InetSocketAddress> remoteAddress();
/**
* Extract the body with the given {@code BodyExtractor}.
* @param extractor the {@code BodyExtractor} that reads from the request

View File

@@ -116,6 +116,11 @@ public class ServerRequestWrapper implements ServerRequest {
return this.delegate.cookies();
}
@Override
public Optional<InetSocketAddress> remoteAddress() {
return this.delegate.remoteAddress();
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor) {
return this.delegate.body(extractor);