Search in sources :

Example 51 with ServerHttpRequest

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 52 with ServerHttpRequest

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 53 with ServerHttpRequest

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 54 with ServerHttpRequest

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) InetSocketAddress(java.net.InetSocketAddress) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 55 with ServerHttpRequest

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)71 HttpHeaders (org.springframework.http.HttpHeaders)26 Test (org.junit.jupiter.api.Test)25 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)20 ServerWebExchange (org.springframework.web.server.ServerWebExchange)19 URI (java.net.URI)17 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)17 Mono (reactor.core.publisher.Mono)13 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)10 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)9 HttpMethod (org.springframework.http.HttpMethod)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Map (java.util.Map)6 HttpStatus (org.springframework.http.HttpStatus)6 MediaType (org.springframework.http.MediaType)6 Flux (reactor.core.publisher.Flux)6 Principal (java.security.Principal)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5