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:
@@ -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())));
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user