workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

[BUG] R2 Object should not move Headers

Open 0x65-e opened this issue 2 years ago • 1 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

What version of workers-rs are you using?

0.0.15

Describe the bug

Reading an Object from R2 and trying to set the headers using write_http_metadata does not work as intended. According to the documentation, it requires moving the Headers object, which makes it impossible to set the Headers for a Response. The Workers R2 API for Javascript makes it clear that this should work:

const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set('etag', object.httpEtag);

return new Response(object.body, {
  headers,
});

This is not possible in the Rust version of the crate. It should be possible to make the function take &mut Headers instead.

Steps To Reproduce

  1. Declare a Headers object
  2. Call object.write_http_metadata(headers);
  3. Try to pass the headers object to a Response, e.g. response.with_headers(headers)

0x65-e avatar Mar 30 '23 06:03 0x65-e

A workaround for now could be to use the .http_metadata() method and write the HTTP headers yourself.

lwansbrough avatar May 02 '23 07:05 lwansbrough