use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ForwardedHeaderTransformerTests method shouldConcatenatePrefixes.
@Test
void shouldConcatenatePrefixes() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Forwarded-Prefix", "/first,/second");
ServerHttpRequest request = this.requestMutator.apply(getRequest(headers));
assertThat(request.getURI()).isEqualTo(new URI("https://example.com/first/second/path"));
assertThat(request.getPath().value()).isEqualTo("/first/second/path");
assertForwardedHeadersRemoved(request);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ForwardedHeaderTransformerTests method shouldConcatenatePrefixesWithTrailingSlashes.
@Test
void shouldConcatenatePrefixesWithTrailingSlashes() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Forwarded-Prefix", "/first/,/second//");
ServerHttpRequest request = this.requestMutator.apply(getRequest(headers));
assertThat(request.getURI()).isEqualTo(new URI("https://example.com/first/second/path"));
assertThat(request.getPath().value()).isEqualTo("/first/second/path");
assertForwardedHeadersRemoved(request);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ForwardedHeaderTransformerTests method xForwardedHeaders.
@Test
void xForwardedHeaders() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Forwarded-Host", "84.198.58.199");
headers.add("X-Forwarded-Port", "443");
headers.add("X-Forwarded-Proto", "https");
headers.add("foo", "bar");
ServerHttpRequest request = this.requestMutator.apply(getRequest(headers));
assertThat(request.getURI()).isEqualTo(new URI("https://84.198.58.199/path"));
assertForwardedHeadersRemoved(request);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ForwardedHeaderTransformerTests method forwardedFor.
@Test
public void forwardedFor() throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add("Forwarded", "for=\"203.0.113.195:4711\";host=84.198.58.199;proto=https");
InetSocketAddress remoteAddress = new InetSocketAddress("example.client", 47011);
ServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, new URI("https://example.com/a%20b?q=a%2Bb")).remoteAddress(remoteAddress).headers(headers).build();
request = this.requestMutator.apply(request);
assertThat(request.getRemoteAddress()).isNotNull();
assertThat(request.getRemoteAddress().getHostName()).isEqualTo("203.0.113.195");
assertThat(request.getRemoteAddress().getPort()).isEqualTo(4711);
}
use of org.springframework.http.server.reactive.ServerHttpRequest in project spring-framework by spring-projects.
the class ForwardedHeaderTransformerTests method shouldNotDoubleEncode.
// SPR-17525
@Test
void shouldNotDoubleEncode() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("Forwarded", "host=84.198.58.199;proto=https");
ServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, new URI("https://example.com/a%20b?q=a%2Bb")).headers(headers).build();
request = this.requestMutator.apply(request);
assertThat(request.getURI()).isEqualTo(new URI("https://84.198.58.199/a%20b?q=a%2Bb"));
assertForwardedHeadersRemoved(request);
}
Aggregations