use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostMultiValuedHeader.
// SPR-11140
@Test
public void fromHttpRequestWithForwardedHostMultiValuedHeader() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(-1);
request.addHeader("X-Forwarded-Host", "a.example.org, b.example.org, c.example.org");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("a.example.org", result.getHost());
assertEquals(-1, result.getPort());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostAndPort.
// SPR-11855
@Test
public void fromHttpRequestWithForwardedHostAndPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(8080);
request.addHeader("X-Forwarded-Host", "foobarhost");
request.addHeader("X-Forwarded-Port", "9090");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("foobarhost", result.getHost());
assertEquals(9090, result.getPort());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestMultipleForwardedHeader.
@Test
public void fromHttpRequestMultipleForwardedHeader() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "host=84.198.58.199;proto=https");
request.addHeader("Forwarded", "proto=ftp; host=1.2.3.4");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https", result.getScheme());
assertEquals("84.198.58.199", result.getHost());
assertEquals("/rest/mobile/users/1", result.getPath());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHost.
@Test
public void fromHttpRequestWithForwardedHost() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(-1);
request.setRequestURI("/mvc-showcase");
request.addHeader("X-Forwarded-Host", "anotherHost");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("http://anotherHost/mvc-showcase", result.toString());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestForwardedHeaderQuoted.
@Test
public void fromHttpRequestForwardedHeaderQuoted() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "proto=\"https\"; host=\"84.198.58.199\"");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https", result.getScheme());
assertEquals("84.198.58.199", result.getHost());
assertEquals("/rest/mobile/users/1", result.getPath());
}
Aggregations