Skip to content

Add Expect 100-continue for UploadPartRequest #4252

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 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AmazonS3-77f8946.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Amazon S3",
"contributor": "",
"description": "Add `Expect: 100-continue` heaer for `UploadPartRequest` so that a request can fail faster if there is a server error."
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.UploadPartRequest;

/**
* Interceptor to add an 'Expect: 100-continue' header to the HTTP Request if it represents a PUT Object request.
*/
@SdkInternalApi
//TODO: This should be generalized for all streaming requests
public final class PutObjectInterceptor implements ExecutionInterceptor {
public final class StreamingRequestInterceptor implements ExecutionInterceptor {
@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context,
ExecutionAttributes executionAttributes) {
if (context.request() instanceof PutObjectRequest) {
if (context.request() instanceof PutObjectRequest || context.request() instanceof UploadPartRequest) {
return context.httpRequest().toBuilder().putHeader("Expect", "100-continue").build();
}
return context.httpRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"asyncClientDecorator": "software.amazon.awssdk.services.s3.internal.client.S3AsyncClientDecorator",
"useGlobalEndpoint": true,
"interceptors": [
"software.amazon.awssdk.services.s3.internal.handlers.PutObjectInterceptor",
"software.amazon.awssdk.services.s3.internal.handlers.StreamingRequestInterceptor",
"software.amazon.awssdk.services.s3.internal.handlers.CreateBucketInterceptor",
"software.amazon.awssdk.services.s3.internal.handlers.CreateMultipartUploadRequestInterceptor",
"software.amazon.awssdk.services.s3.internal.handlers.EnableChunkedEncodingInterceptor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.UploadPartRequest;

public class PutObjectInterceptorTest {
private final PutObjectInterceptor interceptor = new PutObjectInterceptor();
public class StreamingRequestInterceptorTest {
private final StreamingRequestInterceptor interceptor = new StreamingRequestInterceptor();

@Test
public void modifyHttpRequest_setsExpect100Continue_whenSdkRequestIsPutObject() {
Expand All @@ -36,6 +37,16 @@ public void modifyHttpRequest_setsExpect100Continue_whenSdkRequestIsPutObject()
assertThat(modifiedRequest.firstMatchingHeader("Expect")).hasValue("100-continue");
}

@Test
public void modifyHttpRequest_setsExpect100Continue_whenSdkRequestIsUploadPart() {

final SdkHttpRequest modifiedRequest =
interceptor.modifyHttpRequest(modifyHttpRequestContext(UploadPartRequest.builder().build()),
new ExecutionAttributes());

assertThat(modifiedRequest.firstMatchingHeader("Expect")).hasValue("100-continue");
}

@Test
public void modifyHttpRequest_doesNotSetExpect_whenSdkRequestIsNotPutObject() {

Expand Down