workers-rs
workers-rs copied to clipboard
[BUG] R2 Object should not move Headers
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
- Declare a Headers object
- Call
object.write_http_metadata(headers); - Try to pass the headers object to a Response, e.g.
response.with_headers(headers)
A workaround for now could be to use the .http_metadata() method and write the HTTP headers yourself.