fix(s3): set content length for copy object#7884
Conversation
|
Just for my own curiosity, is there any doc mentioning netapp S3 gateway requires content-length header? I didn't find it after some seach |
|
|
||
| fn build(self) -> Result<impl Service> { | ||
| impl S3Builder { | ||
| fn build_backend(self) -> Result<S3Backend> { |
There was a problem hiding this comment.
I needed to test the constructor in a UT, but the construction was not separate, it was happening inside impl Builder, which returned Service, not S3Backend.
Doing this allowed me to test on S3Backend itself w/o duplicating much code.
There was a problem hiding this comment.
Good thought! Try build S3Core instead of building a S3Backend. An arbitrary example:
fn new_test_core() -> CompfsCore {
CompfsCore {
info: ServiceInfo::new("compfs", "", ""),
capability: Capability::default(),
root: PathBuf::from("/data/root"),
dispatcher: Dispatcher::new().unwrap(),
buf_pool: oio::PooledBuf::new(16),
}
}
@dentiny even I couldn't find one that explicitly makes it mandatory. However, I did find their error listing which has one |
I'm not sure this is the best way to handle. :thinking_face:
I'm actually thinking if we could allow users to inject their customized headers
|
|
@dentiny Good point and I agree with you S3 is THE reference implementation. Though I wouldn't consider following S3 to bits is beneficial to us since there are lots of S3-compatible services. We test these S3-compatible services. Nevertheless, you made a valid point. We should not extend our support to all S3-compatible services. How about we track these customized behavior in an issue/discussion? We could either explore some irregular behaviors from various of vendors or set a way for the fix. Meanwhile, we can go ahead with this PR at least. |
| // AWS S3 doesn't care, but some other S3-compat providers | ||
| // require a mandatory `content-length` header to work |
There was a problem hiding this comment.
| // AWS S3 doesn't care, but some other S3-compat providers | |
| // require a mandatory `content-length` header to work | |
| // AWS S3 doesn't define `Content-Length` in CopyObject. S3 allows `Content-Length: 0` silently. | |
| // Some providers require a unspecific `Content-Length`. We allow e.g.,: | |
| // - `NetApp` |
|
Thanks! I create a feature request here to track.
Sure, but I do have a few practical questions:
|
|
@ByteBaker @sudharsansrini do you have a NetApp environment to run behavior tests upon? |
|
Not me, sorry. |
I think this goes against the HTTP spec. The different here is: when a request is missing a content-length, it will be treated as chunked encoding. But if there is a content-length in request, the server will expect this request to have exact bytes of body. So it's unlikely to see a request that declare it has 5GiB but the body is empty. The only exceptions are HEAD responses and 304 responses, where the server must set the correct Content-Length but does not need to return the actual body. However, our case here is not one of those exceptions. In other word, adding So my feeling on "go with the custom header solution" is a way too far for this. |
Which issue does this PR close?
Closes #7821.
Rationale for this change
Some S3-compatible services require
Content-Lengthto be present onCopyObjectrequests, even when the request body is empty. OpenDAL already sends an empty body for S3 copy, so this makes the request explicit by settingContent-Length: 0.What changes are included in this PR?
Content-Length: 0when building S3CopyObjectrequests.s3_copy_object_request, matching existing request-builder patterns.Are there any user-facing changes?
No API changes. This improves compatibility with S3-compatible services.
AI Usage Statement
I used OpenAI Codex to help implement and test this change.