Handle absolute URI in Reactor request.uri()
The request URI returned from HttpServerRequest.uri() typically contains contains an absolute path but could also contain an absolute URI. This commit adds handling for the latter, effectively taking only the absolute path portion. Issue: SPR-16243
This commit is contained in:
parent
b9a1168580
commit
203370a810
|
@ -36,6 +36,7 @@ import org.springframework.lang.Nullable;
|
|||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Adapt {@link ServerHttpRequest} to the Reactor {@link HttpServerRequest}.
|
||||
|
@ -62,7 +63,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
|||
|
||||
private static URI initUri(HttpServerRequest request) throws URISyntaxException {
|
||||
Assert.notNull(request, "'request' must not be null");
|
||||
return new URI(resolveBaseUrl(request).toString() + request.uri());
|
||||
return new URI(resolveBaseUrl(request).toString() + resolveRequestUri(request));
|
||||
}
|
||||
|
||||
private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
|
||||
|
@ -102,6 +103,28 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
|||
return ssl ? "https" : "http";
|
||||
}
|
||||
|
||||
private static String resolveRequestUri(HttpServerRequest request) {
|
||||
String uri = request.uri();
|
||||
for (int i = 0; i < uri.length(); i++) {
|
||||
char c = uri.charAt(i);
|
||||
if (c == '/' || c == '?' || c == '#') {
|
||||
break;
|
||||
}
|
||||
if (c == ':' && (i + 2 < uri.length())) {
|
||||
if (uri.charAt(i + 1) == '/' && uri.charAt(i + 2) == '/') {
|
||||
for (int j = i + 3; j < uri.length(); j++) {
|
||||
c = uri.charAt(j);
|
||||
if (c == '/' || c == '?' || c == '#') {
|
||||
return uri.substring(j);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
private static HttpHeaders initHeaders(HttpServerRequest channel) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
for (String name : channel.requestHeaders().names()) {
|
||||
|
|
Loading…
Reference in New Issue