use of cn.taketoday.http.HttpRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedIPv4Host.
@Test
// SPR-14761
void fromHttpRequestWithForwardedIPv4Host() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("https");
request.setServerName("localhost");
request.setServerPort(-1);
request.setRequestURI("/mvc-showcase");
request.addHeader("Forwarded", "host=192.168.0.1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertThat(result.toString()).isEqualTo("https://192.168.0.1/mvc-showcase");
}
use of cn.taketoday.http.HttpRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHost.
@Test
void fromHttpRequestWithForwardedHost() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("https");
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();
assertThat(result.toString()).isEqualTo("https://anotherHost/mvc-showcase");
}
use of cn.taketoday.http.HttpRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostWithDefaultPort.
@Test
// SPR-11872
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();
assertThat(result.getHost()).isEqualTo("example.org");
assertThat(result.getPort()).isEqualTo(-1);
}
use of cn.taketoday.http.HttpRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedHostWithForwardedScheme.
@Test
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();
assertThat(result.getHost()).isEqualTo("example.org");
assertThat(result.getScheme()).isEqualTo("https");
assertThat(result.getPort()).isEqualTo(-1);
}
use of cn.taketoday.http.HttpRequest in project today-infrastructure by TAKETODAY.
the class UriComponentsBuilderTests method fromHttpRequestForwardedHeaderQuoted.
@Test
void fromHttpRequestForwardedHeaderQuoted() {
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();
assertThat(result.getScheme()).isEqualTo("https");
assertThat(result.getHost()).isEqualTo("84.198.58.199");
assertThat(result.getPath()).isEqualTo("/rest/mobile/users/1");
}
Aggregations