use of org.springframework.http.server.ServletServerHttpRequest in project spring-cloud-netflix by spring-cloud.
the class LocationRewriteFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Route route = routeLocator.getMatchingRoute(urlPathHelper.getPathWithinApplication(ctx.getRequest()));
if (route != null) {
Pair<String, String> lh = locationHeader(ctx);
if (lh != null) {
String location = lh.second();
URI originalRequestUri = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(ctx.getRequest())).build().toUri();
UriComponentsBuilder redirectedUriBuilder = UriComponentsBuilder.fromUriString(location);
UriComponents redirectedUriComps = redirectedUriBuilder.build();
String newPath = getRestoredPath(this.zuulProperties, route, redirectedUriComps);
String modifiedLocation = redirectedUriBuilder.scheme(originalRequestUri.getScheme()).host(originalRequestUri.getHost()).port(originalRequestUri.getPort()).replacePath(newPath).build().toUriString();
lh.setSecond(modifiedLocation);
}
}
return null;
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-cloud-function by spring-cloud.
the class FluxReturnValueHandler method addHeaders.
private void addHeaders(NativeWebRequest webRequest, Message<?> message) {
HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
ServletServerHttpRequest request = new ServletServerHttpRequest(webRequest.getNativeRequest(HttpServletRequest.class));
HttpHeaders headers = HeaderUtils.fromMessage(message.getHeaders(), request.getHeaders());
for (String name : headers.keySet()) {
for (Object object : headers.get(name)) {
response.addHeader(name, object.toString());
}
}
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
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 org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class UriComponentsBuilderTests method fromHttpRequestWithForwardedInvalidIPv6Address.
// gh-26748
@Test
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());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
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");
}
Aggregations