Search in sources :

Example 1 with ServletServerHttpRequest

use of cn.taketoday.http.server.ServletServerHttpRequest in project today-infrastructure by TAKETODAY.

the class UriComponentsBuilderTests method fromHttpRequestForwardedHeaderComma.

@Test
// gh-25737
void fromHttpRequestForwardedHeaderComma() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Forwarded", "for=192.0.2.0,for=192.0.2.1;proto=https;host=192.0.2.3:9090");
    request.setScheme("http");
    request.setServerPort(8080);
    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("192.0.2.3");
    assertThat(result.getPath()).isEqualTo("/rest/mobile/users/1");
    assertThat(result.getPort()).isEqualTo(9090);
    assertThat(result.toUriString()).isEqualTo("https://192.0.2.3:9090/rest/mobile/users/1");
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) HttpRequest(cn.taketoday.http.HttpRequest) ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ServletServerHttpRequest

use of cn.taketoday.http.server.ServletServerHttpRequest in project today-infrastructure by TAKETODAY.

the class UriComponentsBuilderTests method fromHttpRequestWithForwardedInvalidIPv6Address.

@Test
// gh-26748
void fromHttpRequestWithForwardedInvalidIPv6Address() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setScheme("http");
    request.setServerName("localhost");
    request.setServerPort(-1);
    request.setRequestURI("/mvc-showcase");
    request.addHeader("X-Forwarded-Host", "2a02:918:175:ab60:45ee:c12c:dac1:808b");
    HttpRequest httpRequest = new ServletServerHttpRequest(request);
    assertThatIllegalArgumentException().isThrownBy(() -> UriComponentsBuilder.fromHttpRequest(httpRequest).build());
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) HttpRequest(cn.taketoday.http.HttpRequest) ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ServletServerHttpRequest

use of cn.taketoday.http.server.ServletServerHttpRequest in project today-infrastructure by TAKETODAY.

the class UriComponentsBuilderTests method fromHttpRequestForwardedHeaderWithHostPortAndServerPort.

@Test
void fromHttpRequestForwardedHeaderWithHostPortAndServerPort() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Forwarded", "proto=https; host=84.198.58.199:9090");
    request.setScheme("http");
    request.setServerPort(8080);
    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");
    assertThat(result.getPort()).isEqualTo(9090);
    assertThat(result.toUriString()).isEqualTo("https://84.198.58.199:9090/rest/mobile/users/1");
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) HttpRequest(cn.taketoday.http.HttpRequest) ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ServletServerHttpRequest

use of cn.taketoday.http.server.ServletServerHttpRequest in project today-infrastructure by TAKETODAY.

the class UriComponentsBuilderTests method fromHttpRequestWithForwardedIPv6Host.

@Test
// SPR-14761
void fromHttpRequestWithForwardedIPv6Host() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setScheme("http");
    request.setServerName("localhost");
    request.setServerPort(-1);
    request.setRequestURI("/mvc-showcase");
    request.addHeader("X-Forwarded-Host", "[1abc:2abc:3abc::5ABC:6abc]");
    HttpRequest httpRequest = new ServletServerHttpRequest(request);
    UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
    assertThat(result.toString()).isEqualTo("http://[1abc:2abc:3abc::5ABC:6abc]/mvc-showcase");
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) HttpRequest(cn.taketoday.http.HttpRequest) ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ServletServerHttpRequest

use of cn.taketoday.http.server.ServletServerHttpRequest in project today-infrastructure by TAKETODAY.

the class UriComponentsBuilderTests method fromHttpRequestWithForwardedProtoWithDefaultPort.

@Test
// SPR-16262
void fromHttpRequestWithForwardedProtoWithDefaultPort() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setScheme("http");
    request.setServerName("example.org");
    request.setServerPort(10080);
    request.addHeader("X-Forwarded-Proto", "https");
    HttpRequest httpRequest = new ServletServerHttpRequest(request);
    UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
    assertThat(result.getScheme()).isEqualTo("https");
    assertThat(result.getHost()).isEqualTo("example.org");
    assertThat(result.getPort()).isEqualTo(-1);
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) HttpRequest(cn.taketoday.http.HttpRequest) ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ServletServerHttpRequest (cn.taketoday.http.server.ServletServerHttpRequest)61 Test (org.junit.jupiter.api.Test)56 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)56 HttpRequest (cn.taketoday.http.HttpRequest)54 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)32 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)29 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 ConversionNotSupportedException (cn.taketoday.beans.ConversionNotSupportedException)1 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)1 MethodParameter (cn.taketoday.core.MethodParameter)1 HttpInputMessage (cn.taketoday.http.HttpInputMessage)1 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (cn.taketoday.http.converter.HttpMessageNotWritableException)1 ServletServerHttpResponse (cn.taketoday.http.server.ServletServerHttpResponse)1 BindException (cn.taketoday.validation.BindException)1 HttpMediaTypeNotAcceptableException (cn.taketoday.web.HttpMediaTypeNotAcceptableException)1 HttpMediaTypeNotSupportedException (cn.taketoday.web.HttpMediaTypeNotSupportedException)1 HttpRequestMethodNotSupportedException (cn.taketoday.web.HttpRequestMethodNotSupportedException)1 MethodArgumentNotValidException (cn.taketoday.web.bind.MethodArgumentNotValidException)1 MissingPathVariableException (cn.taketoday.web.bind.MissingPathVariableException)1