actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Can not set Content-Length response header for S3 protocol

Open zrleblanc opened this issue 1 year ago • 0 comments

We just ran into issue #1439 when implementing S3 server code. While the work around works for "small" responses where we can just generate some random data to be thrown away for the body, when this needs to be done for muliti-gigabyte files it becomes very expensive and unnecessary. I'd like to re-open the discussion around not being able to manually set this header

Expected Behavior

Be able to set the Content-Length header in the response builder for S3 compatibility of large files. https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadObject.html

Current Behavior

The Content-Length header can only be set programmaticly by including a body which is then calculated the length and then discarded. This is fine for "small" bodies, but multi-gigabyte bodies is impractical.

Possible Solution

Allow for manually specified Content-Length response header that overrides the computed value with big warnings in the documentation saying that it is highly discouraged to override this value.

Steps to Reproduce (for bugs)

  1. Set Content-Length in the response header >0
  2. Do not include a body in the response
  3. Check the Content-Length response header value in a client is 0.

Context

It is common practice in S3 to HEAD a file to get things like size and ETAG in order to provide download progress bars for downloading of large files and checking the integrity of the file. Not being able to provide accurate size efficiently breaks these progress bars.

Your Environment

  • Rust Version (I.e, output of rustc -V):
  • Actix Web Version:

zrleblanc avatar Jun 27 '24 16:06 zrleblanc