-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat zero-byte responses from HTTP clients as not having content whe…
…n it comes to creating an SDK HTTP full request. This fixes issues like #1216 where HEAD request responses have a content-length but no payload, confusing the SDK.
- Loading branch information
Showing
7 changed files
with
122 additions
and
65 deletions.
There are no files selected for viewing
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": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Treat zero-byte responses from async HTTP clients as not having a payload, regardless of the response content-length. This fixes an issue that could cause HEAD responses (e.g. s3's headObject responses) with a content-length specified from being treated as having a payload. This fixes issues like [#1216](https://github.com/aws/aws-sdk-java-v2/issues/1216) where the SDK attempts to read data from the response based on the content-length, not based on whether there was actually a payload." | ||
} |
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
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
64 changes: 64 additions & 0 deletions
64
services/s3/src/it/java/software/amazon/awssdk/services/s3/HeadObjectIntegrationTest.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,64 @@ | ||
/* | ||
* 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.services.s3; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.zip.GZIPOutputStream; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.model.HeadObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.HeadObjectResponse; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
|
||
public class HeadObjectIntegrationTest extends S3IntegrationTestBase { | ||
private static final String BUCKET = temporaryBucketName(HeadObjectIntegrationTest.class); | ||
|
||
private static final String GZIPPED_KEY = "some-key"; | ||
|
||
@BeforeClass | ||
public static void setupFixture() throws IOException { | ||
createBucket(BUCKET); | ||
|
||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
GZIPOutputStream gzos = new GZIPOutputStream(baos); | ||
gzos.write("Test".getBytes(StandardCharsets.UTF_8)); | ||
|
||
s3.putObject(PutObjectRequest.builder() | ||
.bucket(BUCKET) | ||
.key(GZIPPED_KEY) | ||
.contentEncoding("gzip") | ||
.build(), | ||
RequestBody.fromBytes(baos.toByteArray())); | ||
} | ||
|
||
@Test | ||
public void asyncClientSupportsGzippedObjects() { | ||
HeadObjectResponse response = s3Async.headObject(r -> r.bucket(BUCKET).key(GZIPPED_KEY)).join(); | ||
assertThat(response.contentEncoding()).isEqualTo("gzip"); | ||
} | ||
|
||
@Test | ||
public void syncClientSupportsGzippedObjects() { | ||
HeadObjectResponse response = s3.headObject(r -> r.bucket(BUCKET).key(GZIPPED_KEY)); | ||
assertThat(response.contentEncoding()).isEqualTo("gzip"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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