Skip to content

Disable Apache normalization #1224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ApacheHttpClient-d9de03d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "Apache Http Client",
"type": "bugfix",
"description": "Disable apache normalization to handle breaking change introduced in apache httpclient `4.5.7`. See [aws/aws-sdk-java[#1919](https://github.com/aws/aws-sdk-java-v2/issues/1919)](https://github.com/aws/aws-sdk-java/issues/1919) for more information."
}
5 changes: 5 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-f344377.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "AWS SDK for Java v2",
"type": "feature",
"description": "Update Apache http client version to `4.5.9`."
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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,16 +24,19 @@
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;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.http.apache.ProxyConfiguration;
import software.amazon.awssdk.utils.Logger;

@SdkInternalApi
public final class ApacheUtils {
private static final Logger logger = Logger.loggerFor(ApacheUtils.class);

private ApacheUtils() {
}
Expand All @@ -59,10 +62,41 @@ 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
logger.warn(() -> "NoSuchMethodError was thrown when disabling normalizeUri. This indicates you are using an old "
+ "version (< 4.5.8) of Apache http "
+ "client. It is recommended to use http client version >= 4.5.9 to avoid the breaking change "
+ "introduced in apache client 4.5.7 and the latency in exception handling. "
+ "See https://github.com/aws/aws-sdk-java/issues/1919 for more information");
}
}

/**
* 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 @@ -145,7 +145,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.9</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