Skip to content

Commit b9c9991

Browse files
committed
Pass through URL path without reinterpretation
Previously percent-encoded URLs did not round-trip through the URI normalization, preventing use of S3 signed URLs.
1 parent 1b798d7 commit b9c9991

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/main/java/com/bouncestorage/chaoshttpproxy/ChaosHttpProxyHandler.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,15 @@ public void handle(String target, Request baseRequest,
9696
HostAndPort hostAndPort = HostAndPort.fromString(request.getHeader(
9797
HttpHeaders.HOST));
9898
String queryString = request.getQueryString();
99-
URI uri;
100-
try {
101-
uri = new URI(request.getScheme(),
102-
/*userInfo=*/ null,
103-
hostAndPort.getHost(),
104-
hostAndPort.hasPort() ? hostAndPort.getPort() : 80,
105-
request.getRequestURI(),
106-
queryString,
107-
/*fragment=*/ null);
108-
} catch (URISyntaxException use) {
109-
throw new IOException(use);
110-
}
99+
// Intentionally create URL with String to avoid percent encoding
100+
// issues.
101+
URI uri = URI.create(
102+
request.getScheme() + "://" +
103+
hostAndPort.getHost() + ":" +
104+
// TODO: does this make sense for HTTPS?
105+
(hostAndPort.hasPort() ? hostAndPort.getPort() : 80) +
106+
request.getRequestURI() +
107+
(queryString != null ? "?" + queryString : ""));
111108
logger.debug("uri: {}", uri);
112109
URI redirectedUri = redirects.get(uri);
113110
if (redirectedUri != null) {
@@ -159,7 +156,7 @@ public void handle(String target, Request baseRequest,
159156
// TODO: random limit
160157
ByteStreams.limit(is, 1024) : is;
161158
org.eclipse.jetty.client.api.Request clientRequest = client
162-
.newRequest(uri.toString())
159+
.newRequest(uri)
163160
.method(request.getMethod());
164161
long userContentLength = -1;
165162
for (String headerName :

0 commit comments

Comments
 (0)