@@ -150,19 +150,33 @@ public final class AwsEndpointProviderUtils {
150
150
String clientEndpointPath = clientEndpoint.getRawPath();
151
151
152
152
// [client endpoint path]/[request path]
153
- String requestPath = request.getUri().getRawPath ();
153
+ String requestPath = request.encodedPath ();
154
154
155
155
// [client endpoint path]/[additional path added by resolver]
156
156
String resolvedUriPath = resolvedUri.getRawPath();
157
157
158
- // our goal is to construct [client endpoint path]/[additional path added by resolver]/[request path], so we
159
- // just need to strip the client endpoint path from the marshalled request path to isolate just the part added
160
- // by the marshaller
161
- String requestPathWithClientPathRemoved = StringUtils.replaceOnce(requestPath, clientEndpointPath, "");
162
- String finalPath = SdkHttpUtils.appendUri(resolvedUriPath, requestPathWithClientPathRemoved);
158
+ String finalPath = requestPath;
159
+
160
+ // If there is an additional path added by resolver, i.e., [additional path added by resolver] not null,
161
+ // we need to combine the path
162
+ if (!resolvedUriPath.equals(clientEndpointPath)) {
163
+ finalPath = combinePath(clientEndpointPath, requestPath, resolvedUriPath);
164
+ }
163
165
164
166
return request.toBuilder().protocol(resolvedUri.getScheme()).host(resolvedUri.getHost()).port(resolvedUri.getPort())
165
- .encodedPath(finalPath).build();
167
+ .encodedPath(finalPath).build();
168
+ }
169
+
170
+ /**
171
+ * Our goal is to construct [client endpoint path]/[additional path added by resolver]/[request path], so we just need to
172
+ * strip the client endpoint path from the marshalled request path to isolate just the part added by the marshaller. Trailing
173
+ * slash is removed from client endpoint path before stripping because it could cause the leading slash to be removed from the
174
+ * request path: e.g., StringUtils.replaceOnce("/", "//test", "") generates "/test" and the expected result is "//test"
175
+ */
176
+ private static String combinePath(String clientEndpointPath, String requestPath, String resolvedUriPath) {
177
+ String requestPathWithClientPathRemoved = StringUtils.replaceOnce(requestPath, clientEndpointPath, "");
178
+ String finalPath = SdkHttpUtils.appendUri(resolvedUriPath, requestPathWithClientPathRemoved);
179
+ return finalPath;
166
180
}
167
181
168
182
public static AwsRequest addHeaders(AwsRequest request, Map<String, List<String>> headers) {
0 commit comments