cloudflare-docs icon indicating copy to clipboard operation
cloudflare-docs copied to clipboard

R2Object.httpEtag contains W/, but R2Bucket.get throws TypeError when etag has W/

Open yonran opened this issue 3 years ago • 0 comments

Which Cloudflare product does this pertain to?

R2

Existing documentation URL(s)

https://developers.cloudflare.com/r2/examples/demo-worker/ https://developers.cloudflare.com/r2/runtime-apis/#conditional-operations

Section that requires update

Either the demo needs to be updated, or the R2Object.get({…, onlyIf: Headers}) API needs to be fixed or clarified.

What needs to change?

R2Object.httpEtag returns a weak validator prefixed with W/, but R2Object.get does not support reading this header value.

How should it change?

R2Object.get should clarify whether it supports onlyIf Headers from the request.

Additional information

When I tried the R2 worker demo and refreshed the page in the browser, it alternated between a success page an an error page:

Screen Shot 2022-08-08 at 5 12 37 PM

When I enabled the Real-time Logs, I observed that the call to MY_BUCKET.get({…, onlyIf: request.headers}) threw a TypeError: “ETag in HTTP header needs to be wrapped in quotes W/"52af2bc97aef22023c97c7874b569d0d").”

Screen Shot 2022-08-08 at 5 23 31 PM

The source of the worker module (live, github) contains the following for handling GET requests to R2:

        const object = await env.MY_BUCKET.get(objectName, {
          range,
          onlyIf: request.headers,
        })
        …
        headers.set('etag', object.httpEtag)

If it matters, I used the S3 API to upload the object along with the etag.

yonran avatar Aug 09 '22 00:08 yonran