Skip to content

Commit

Permalink
Disable Apache normalization to handle breaking change introduced in …
Browse files Browse the repository at this point in the history
…v4.5.7

See aws/aws-sdk-java#1919 for more details.
  • Loading branch information
varunnvs92 committed Apr 23, 2019
1 parent af22896 commit 26bd29e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* <p>
* 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.
* </p>
*
* 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.
*/
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<aspectj.version>1.8.2</aspectj.version>

<jre.version>1.8</jre.version>
<httpcomponents.httpclient.version>4.5.6</httpcomponents.httpclient.version>
<httpcomponents.httpclient.version>4.5.8</httpcomponents.httpclient.version>
<httpcomponents.httpcore.version>4.4.10</httpcomponents.httpcore.version>

<!-- These properties are used by cucumber tests related code -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 26bd29e

Please sign in to comment.