Skip to content

Commit

Permalink
Remove "Host" header in Aws API calls
Browse files Browse the repository at this point in the history
HttpClient in J11 will raise  `java.lang.IllegalArgumentException: restricted header name: "Host"` if a "Host" header is provided - there are overrides for this in J12 onwards, but not possible in J11.
  • Loading branch information
JamesHazelcast committed Oct 13, 2023
1 parent 3c52c06 commit 53289d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hazelcast/src/main/java/com/hazelcast/aws/AwsEc2Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ private Map<String, String> createHeaders(Map<String, String> attributes, AwsCre
if (!StringUtil.isNullOrEmptyAfterTrim(credentials.getToken())) {
headers.put("X-Amz-Security-Token", credentials.getToken());
}
headers.put("Host", endpoint);
// "Host" header is restricted with HttpClient in J11 - when we send our request,
// it is automatically set to the URL host (which in this case is `endpoint` still)
String timestamp = currentTimestamp(clock);
headers.put("X-Amz-Date", timestamp);
headers.put("Authorization", requestSigner.authHeader(attributes, headers, "", credentials, timestamp, "GET"));
Expand Down
3 changes: 2 additions & 1 deletion hazelcast/src/main/java/com/hazelcast/aws/AwsEcsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private Map<String, String> createHeaders(String body, AwsCredentials credential
if (!StringUtil.isNullOrEmptyAfterTrim(credentials.getToken())) {
headers.put("X-Amz-Security-Token", credentials.getToken());
}
headers.put("Host", endpoint);
// "Host" header is restricted with HttpClient in J11 - when we send our request,
// it is automatically set to the URL host (which in this case is `endpoint` still)
headers.put("X-Amz-Target", String.format("AmazonEC2ContainerServiceV20141113.%s", awsTargetAction));
headers.put("Content-Type", "application/x-amz-json-1.1");
headers.put("Accept-Encoding", "identity");
Expand Down

0 comments on commit 53289d4

Please sign in to comment.