Do not double-encode URIs when they are being modified

Previously, when UriModifyingOperationPreprocessor modified a URI it
would always encode it. However, the URIs being modified will always
have been encoded, resulting in double-encoding of the URI.

This commit updates UriModifyingOperationPreprocessor to tell
UriComponentsBuilder that the components have already been encoded.
This ensures that they are not encoded for a second time when the URI
is being built.

Closes gh-211
This commit is contained in:
Andy Wilkinson
2016-04-04 10:47:11 +01:00
parent 6ea6dcf996
commit 488d36d4bf
2 changed files with 11 additions and 1 deletions

View File

@@ -140,7 +140,7 @@ public final class UriModifyingOperationPreprocessor implements OperationPreproc
modifiedHeaders.set(HttpHeaders.HOST, this.host);
}
return this.contentModifyingDelegate.preprocess(
new OperationRequestFactory().create(uriBuilder.build().toUri(),
new OperationRequestFactory().create(uriBuilder.build(true).toUri(),
request.getMethod(), request.getContent(), modifiedHeaders,
request.getParameters(), modify(request.getParts())));
}

View File

@@ -307,6 +307,16 @@ public class UriModifyingOperationPreprocessorTests {
is(equalTo("The uri 'http://api.example.com:12345' should be used")));
}
@Test
public void modifiedUriDoesNotGetDoubleEncoded() {
this.preprocessor.scheme("https");
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
assertThat(processed.getUri(),
is(equalTo(URI.create("https://localhost:12345?foo=%7B%7D"))));
}
private OperationRequest createRequestWithUri(String uri) {
return this.requestFactory.create(URI.create(uri), HttpMethod.GET, new byte[0],
new HttpHeaders(), new Parameters(),