Skip to content

Commit 86f8812

Browse files
mtdowlingadwsingh
authored andcommitted
Fix URI concat issue with HttpClientProtocol
1 parent af679ed commit 86f8812

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

client/client-http/src/main/java/software/amazon/smithy/java/client/http/HttpClientProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public HttpRequest setServiceEndpoint(HttpRequest request, Endpoint endpoint) {
5454
// If a path is set on the service endpoint, concatenate it with the path of the request.
5555
if (uri.getRawPath() != null && !uri.getRawPath().isEmpty()) {
5656
builder.path(uri.getRawPath());
57-
builder.concatPath(request.uri().getPath());
57+
builder.concatPath(request.uri().getRawPath());
5858
}
5959

6060
var requestBuilder = request.toBuilder();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.java.client.http;
7+
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.hamcrest.Matchers.equalTo;
10+
11+
import java.net.URI;
12+
import java.util.concurrent.CompletableFuture;
13+
import org.junit.jupiter.api.Test;
14+
import software.amazon.smithy.java.client.core.endpoint.Endpoint;
15+
import software.amazon.smithy.java.context.Context;
16+
import software.amazon.smithy.java.core.schema.ApiOperation;
17+
import software.amazon.smithy.java.core.schema.SerializableStruct;
18+
import software.amazon.smithy.java.core.serde.Codec;
19+
import software.amazon.smithy.java.core.serde.TypeRegistry;
20+
import software.amazon.smithy.java.http.api.HttpRequest;
21+
import software.amazon.smithy.java.http.api.HttpResponse;
22+
import software.amazon.smithy.model.shapes.ShapeId;
23+
24+
public class HttpClientProtocolTest {
25+
@Test
26+
public void mergesPaths() throws Exception {
27+
var hcp = new HttpClientProtocol(ShapeId.from("foo#Bar")) {
28+
@Override
29+
public Codec payloadCodec() {
30+
return null;
31+
}
32+
33+
@Override
34+
public <I extends SerializableStruct, O extends SerializableStruct> HttpRequest createRequest(
35+
ApiOperation<I, O> operation,
36+
I input,
37+
Context context,
38+
URI endpoint
39+
) {
40+
return null;
41+
}
42+
43+
@Override
44+
public <I extends SerializableStruct,
45+
O extends SerializableStruct> CompletableFuture<O> deserializeResponse(
46+
ApiOperation<I, O> operation,
47+
Context context,
48+
TypeRegistry errorRegistry,
49+
HttpRequest request,
50+
HttpResponse response
51+
) {
52+
return null;
53+
}
54+
};
55+
56+
var endpoint = Endpoint.builder().uri("https://example.com/foo%20/bar").build();
57+
var request = HttpRequest.builder()
58+
.method("GET")
59+
.uri(new URI("/bam%20"))
60+
.build();
61+
var merged = hcp.setServiceEndpoint(request, endpoint);
62+
63+
// It concats the endpoints and maintains percent encoding.
64+
assertThat(merged.uri().toString(), equalTo("https://example.com/foo%20/bar/bam%20"));
65+
}
66+
}

0 commit comments

Comments
 (0)