Skip 'Expect: 100-continue' header for zero-length S3 streaming requests#6465
Skip 'Expect: 100-continue' header for zero-length S3 streaming requests#6465
Conversation
bad553d to
32853df
Compare
| return context.requestBody() | ||
| .flatMap(RequestBody::optionalContentLength) | ||
| .map(length -> length != 0L) | ||
| .orElse(true); |
There was a problem hiding this comment.
What about async request body? The length could also be sourced from the request itself, i.e, putObjectRequest.contentLength(). Should we check header instead? It could be content-length or x-amz-decoded-content-length
There was a problem hiding this comment.
+1, we should probably give priority to x-amz-decoded-content-length and just fall back to content-length. If the decoded length is present and 0, then it's just the trailer and I don't think we need to use expect: 100-continue for that.
...n/java/software/amazon/awssdk/services/s3/internal/handlers/StreamingRequestInterceptor.java
Outdated
Show resolved
Hide resolved
75beb91 to
04e9ec5
Compare
| "type": "bugfix", | ||
| "category": "Amazon S3", | ||
| "contributor": "", | ||
| "description": "Fix StreamingRequestInterceptor to skip Expect: 100-continue header when PutObject or UploadPart requests have zero content length." |
There was a problem hiding this comment.
nit: StreamingRequestInterceptor is an internal class, can we remove the mention of it?
0a60323 to
14e35ba
Compare
|
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |



Motivation and Context
Fix for #6459
Per RFC 9110 Section 10.1.1, clients MUST NOT generate a 100-continue expectation in requests that do not include content. Currently, the SDK adds the
Expect: 100-continueheader to all S3 PutObject and UploadPart requests, including those with zero-length content.This causes issues with sync HTTP clients (e.g., Apache HttpClient) that reuse connections. When a zero-length request is sent with the Expect header, the server may close the connection after receiving the empty content, but the client attempts to reuse it, leading to connection errors.
RFC 9110 Reference:
Modifications
Updated
StreamingRequestInterceptorto skip adding theExpect: 100-continueheader when:Key Changes:
shouldAddExpectContinueHeader()method to check for zero-length contentBehavior:
Optional.empty()0L> 0LTesting
Added test coverage in
StreamingRequestInterceptorTest:Screenshots (if appropriate)
N/A - Code-only change
Types of changes
License
Notes
Apache 5.x
https://github.com/arturobernalg/httpcomponents-client/blob/237b5f85f743c94d9be2d26d396130bc2053f2ef/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestExpectContinue.java#L85-L88
Apache 4.5.x
https://github.com/apache/httpcomponents-client/blob/54900db4653d7f207477e6ee40135b88e9bcf832/httpclient/src/main/java/org/apache/http/client/protocol/RequestExpectContinue.java#L73-L75