use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostWithDefaultPort.
// SPR-11872
@Test
public void fromHttpRequestWithForwardedHostWithDefaultPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(10080);
request.addHeader("X-Forwarded-Host", "example.org");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("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 fromHttpRequestWithForwardedHostIncludingPort.
// SPR-10701
@Test
public void fromHttpRequestWithForwardedHostIncludingPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(-1);
request.setRequestURI("/mvc-showcase");
request.addHeader("X-Forwarded-Host", "webtest.foo.bar.com:443");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("webtest.foo.bar.com", result.getHost());
assertEquals(443, result.getPort());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestResetsPortBeforeSettingIt.
// SPR-12771
@Test
public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("X-Forwarded-Proto", "https");
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", 443);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(80);
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(-1, result.getPort());
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 fromHttpRequestWithForwardedHostWithForwardedScheme.
@Test
public void fromHttpRequestWithForwardedHostWithForwardedScheme() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(10080);
request.addHeader("X-Forwarded-Host", "example.org");
request.addHeader("X-Forwarded-Proto", "https");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("example.org", result.getHost());
assertEquals("https", result.getScheme());
assertEquals(-1, result.getPort());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestMultipleForwardedHeaderComma.
@Test
public void fromHttpRequestMultipleForwardedHeaderComma() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "host=84.198.58.199 ;proto=https, 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());
}
Aggregations