Merge branch '5.2.x'
# Conflicts: # build.gradle # spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java # spring-web/src/main/java/org/springframework/http/HttpHeaders.java # spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java
This commit is contained in:
@@ -385,7 +385,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
* An empty {@code HttpHeaders} instance (immutable).
|
||||
* @since 5.0
|
||||
*/
|
||||
public static final HttpHeaders EMPTY = new ReadOnlyHttpHeaders(new HttpHeaders(new LinkedMultiValueMap<>(0)));
|
||||
public static final HttpHeaders EMPTY = new ReadOnlyHttpHeaders(new LinkedMultiValueMap<>());
|
||||
|
||||
/**
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match".
|
||||
@@ -1769,19 +1769,21 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
|
||||
|
||||
/**
|
||||
* Apply a read-only {@code HttpHeaders} wrapper around the given headers
|
||||
* that also caches the parsed representations of the "Accept" and
|
||||
* "Content-Type" headers.
|
||||
* Apply a read-only {@code HttpHeaders} wrapper around the given headers, if necessary.
|
||||
* <p>Also caches the parsed representations of the "Accept" and "Content-Type" headers.
|
||||
* @param headers the headers to expose
|
||||
* @return a read-only variant of the headers, or the original headers as-is
|
||||
*/
|
||||
public static HttpHeaders readOnlyHttpHeaders(MultiValueMap<String, String> headers) {
|
||||
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
|
||||
Assert.notNull(headers, "HttpHeaders must not be null");
|
||||
return (headers instanceof ReadOnlyHttpHeaders ?
|
||||
(HttpHeaders) headers : new ReadOnlyHttpHeaders(headers));
|
||||
return (headers instanceof ReadOnlyHttpHeaders ? headers : new ReadOnlyHttpHeaders(headers.headers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any read-only wrapper that may have been previously applied around
|
||||
* the given headers via {@link #readOnlyHttpHeaders(MultiValueMap)}.
|
||||
* the given headers via {@link #readOnlyHttpHeaders(HttpHeaders)}.
|
||||
* @param headers the headers to expose
|
||||
* @return a writable variant of the headers, or the original headers as-is
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public static HttpHeaders writableHttpHeaders(HttpHeaders headers) {
|
||||
|
||||
@@ -195,20 +195,20 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
return this.originalRequest.getCookies();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.originalRequest.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return this.originalRequest.getLocalAddress();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.originalRequest.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected SslInfo initSslInfo() {
|
||||
return this.sslInfo;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
else {
|
||||
InetSocketAddress localAddress = request.hostAddress();
|
||||
Assert.state(localAddress != null, "No host address available");
|
||||
return new URI(scheme, null, localAddress.getHostString(),
|
||||
localAddress.getPort(), null, null, null);
|
||||
}
|
||||
@@ -145,13 +146,15 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.request.remoteAddress();
|
||||
@Nullable
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return this.request.hostAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return this.request.hostAddress();
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.request.remoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -65,19 +65,19 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage
|
||||
MultiValueMap<String, HttpCookie> getCookies();
|
||||
|
||||
/**
|
||||
* Return the remote address where this request is connected to, if available.
|
||||
* Return the local address the request was accepted on, if available.
|
||||
* @since 5.2.3
|
||||
*/
|
||||
@Nullable
|
||||
default InetSocketAddress getRemoteAddress() {
|
||||
default InetSocketAddress getLocalAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the local address the request was accepted on, if available.
|
||||
* 5.2.3
|
||||
* Return the remote address where this request is connected to, if available.
|
||||
*/
|
||||
@Nullable
|
||||
default InetSocketAddress getLocalAddress() {
|
||||
default InetSocketAddress getRemoteAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -97,17 +97,19 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return getDelegate().getLocalAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return getDelegate().getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return getDelegate().getLocalAddress();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SslInfo getSslInfo() {
|
||||
return getDelegate().getSslInfo();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -179,13 +180,15 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort());
|
||||
@NonNull
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return new InetSocketAddress(this.request.getLocalAddr(), this.request.getLocalPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return new InetSocketAddress(this.request.getLocalAddr(), this.request.getLocalPort());
|
||||
@NonNull
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -93,13 +93,15 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.exchange.getSourceAddress();
|
||||
@Nullable
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return this.exchange.getDestinationAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress() {
|
||||
return this.exchange.getDestinationAddress();
|
||||
@Nullable
|
||||
public InetSocketAddress getRemoteAddress() {
|
||||
return this.exchange.getSourceAddress();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user