diff --git a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java index 2f80c796ca09..5ae3c9fb0396 100644 --- a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java +++ b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java @@ -72,6 +72,8 @@ private void addRequestConfig(final HttpRequestBase base, .setSocketTimeout(saturatedCast(requestConfig.socketTimeout().toMillis())) .setLocalAddress(requestConfig.localAddress()); + ApacheUtils.disableNormalizeUri(requestConfigBuilder); + /* * Enable 100-continue support for PUT operations, since this is * where we're potentially uploading large amounts of data and want diff --git a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java index 7b42eb6820db..ba7feb313a48 100644 --- a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java +++ b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java @@ -24,6 +24,7 @@ import org.apache.http.auth.NTCredentials; import org.apache.http.client.AuthCache; import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.auth.BasicScheme; @@ -59,10 +60,36 @@ public static HttpEntity newBufferedHttpEntity(HttpEntity entity) { public static HttpClientContext newClientContext(ProxyConfiguration proxyConfiguration) { HttpClientContext clientContext = new HttpClientContext(); addPreemptiveAuthenticationProxy(clientContext, proxyConfiguration); + + RequestConfig.Builder builder = RequestConfig.custom(); + disableNormalizeUri(builder); + + clientContext.setRequestConfig(builder.build()); return clientContext; } + /** + * From Apache v4.5.8, normalization should be disabled or AWS requests with special characters in URI path will fail + * with Signature Errors. + *

+ * setNormalizeUri is added only in 4.5.8, so customers using the latest version of SDK with old versions (4.5.6 or less) + * of Apache httpclient will see NoSuchMethodError. Hence this method will suppress the error. + * + * Do not use Apache version 4.5.7 as it breaks URI paths with special characters and there is no option + * to disable normalization. + *

+ * + * For more information, See https://github.com/aws/aws-sdk-java/issues/1919 + */ + public static void disableNormalizeUri(RequestConfig.Builder requestConfigBuilder) { + try { + requestConfigBuilder.setNormalizeUri(false); + } catch (NoSuchMethodError error) { + // setNormalizeUri method was added in httpclient 4.5.8 + } + } + /** * Returns a new Credentials Provider for use with proxy authentication. */ diff --git a/pom.xml b/pom.xml index f616c3d2255e..7fb6a7d1b972 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ 1.8.2 1.8 - 4.5.6 + 4.5.8 4.4.10 diff --git a/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java b/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java index d429f9f6d877..761dd0a201e5 100644 --- a/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java +++ b/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java @@ -89,8 +89,9 @@ public static void createResources() throws Exception { createKey("key-" + numberFormatter.format(i)); } createKey("aaaaa"); - createKey("aaaaa/aaaaa"); createKey("aaaaa/aaaaa/aaaaa"); + createKey("aaaaa/aaaaa+a"); + createKey("aaaaa/aaaaa//aaaaa"); createKey(KEY_NAME_WITH_SPECIAL_CHARS); }