cloudflare / cloudflare/workers-rs
[BUG] R2 Object should not move Headers
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 429
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 7
Description
### 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](https://docs.rs/worker/latest/worker/struct.Object.html#method.write_http_metadata), it requires moving the Headers object, which makes it impossible to set the Headers for a Response. The [Workers R2 API for Javascript](https://developers.cloudflare.com/r2/api/workers/workers-api-usage/#5-access-your-r2-bucket-from-your-worker) makes it clear that this should work:
```javascript
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)`
Contributor guide
Assessment
This issue has not been assessed yet.