Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import static java.util.Objects.isNull;

/**
* Adapt {@link ServerHttpRequest} to the Reactor {@link HttpServerRequest}.
*
Expand All @@ -58,10 +60,21 @@ public ReactorServerHttpRequest(HttpServerRequest request, NettyDataBufferFactor
private static URI initUri(HttpServerRequest channel) {
Assert.notNull(channel, "'channel' must not be null");
InetSocketAddress address = channel.remoteAddress();
String requestUri = channel.uri();
String requestUri = squashSlashes(channel.uri());
return (address != null ? getBaseUrl(address).resolve(requestUri) : URI.create(requestUri));
}

/**
* Remove redundant slashes from request URI-string
*
* <p>
* http://example.com/// -> http://example.com/
* </p>
*/
private static String squashSlashes(String uri) {
return isNull(uri) ? uri : uri.replaceAll("/{2,}", "/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this collapse http://example.com/// to http:/example.com/?

Copy link
Author

@daggerok daggerok May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shredder121, you are talking about URL, but not URI, which actually i'm replacing..
so answering on your question: no, it wouldn't, it should collapse only URI: /// -> /

Copy link

@luyuanwan luyuanwan May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think function squashSlashes should move to some tool utility class. :)

}

private static URI getBaseUrl(InetSocketAddress address) {
try {
return new URI(null, null, address.getHostString(), address.getPort(), null, null, null);
Expand Down