-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle header lists in URLConnection client (#4897)
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changes/next-release/bugfix-URLConnectionClient-71a8135.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "URL Connection Client", | ||
"contributor": "", | ||
"description": "Fix a bug where headers with multiple values don't have all values for that header sent on the wire. This leads to signature mismatch exceptions.\n\nFixes [#4746](https://github.com/aws/aws-sdk-java-v2/issues/4746)." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ction-client/src/test/java/software/amazon/awssdk/http/urlconnection/HeadersListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.http.urlconnection; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.http.ContentStreamProvider; | ||
import software.amazon.awssdk.http.HttpExecuteRequest; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.SdkHttpFullRequest; | ||
import software.amazon.awssdk.http.SdkHttpMethod; | ||
|
||
public class HeadersListTest { | ||
private static final WireMockServer WIRE_MOCK = new WireMockServer(0); | ||
private static SdkHttpClient client; | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
WIRE_MOCK.start(); | ||
client = UrlConnectionHttpClient.create(); | ||
} | ||
|
||
@AfterAll | ||
public static void teardown() { | ||
client.close(); | ||
WIRE_MOCK.stop(); | ||
} | ||
|
||
@Test | ||
public void execute_requestHeaderHasMultipleValues_allValuesSent() throws IOException { | ||
ContentStreamProvider provider = () -> new ByteArrayInputStream(new byte[0]); | ||
SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder() | ||
.method(SdkHttpMethod.PUT) | ||
.host("localhost") | ||
.port(WIRE_MOCK.port()) | ||
.protocol("http") | ||
.putHeader("my-header", Arrays.asList("value1", "value2")) | ||
.encodedPath("/test") | ||
.build(); | ||
|
||
HttpExecuteRequest request = HttpExecuteRequest.builder() | ||
.request(httpRequest) | ||
.contentStreamProvider(provider) | ||
.build(); | ||
|
||
client.prepareRequest(request).call(); | ||
|
||
WIRE_MOCK.verify(putRequestedFor(urlEqualTo("/test")) | ||
.withHeader("my-header", equalTo("value1,value2"))); | ||
} | ||
} |