Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use eTags #358

Open
Bananas-Are-Yellow opened this issue Jul 25, 2023 · 1 comment
Open

How to use eTags #358

Bananas-Are-Yellow opened this issue Jul 25, 2023 · 1 comment
Labels

Comments

@Bananas-Are-Yellow
Copy link

According to the Dropbox for HTTP Developers documentation:

These endpoints also support HTTP GET along with ETag-based caching (If-None-Match) ...

ETags are returned for certain calls, and DownloadAsync is one of them.

Dropbox API v2 does not give me access to the request headers or the response headers, but according to this forum post, the eTag value can be found in the rev property. Well almost, you have to prefix it with the weak eTag validator prefix:

  • rev: "5f99c43bf6a930044b034"
  • ETag: W/"5f99c43bf6a930044b034"

That value is the rev (and hence the eTag) for /path/to/file.txt in my Dropbox folder.

Using curl, I can verify that If-None-Match: W/"5f99c43bf6a930044b034" does indeed work:

curl -i -X POST https://content.dropboxapi.com/2/files/download \
    --header 'Authorization: Bearer ...' \
    --header 'Dropbox-API-Arg: {"path":"/path/to/file.txt}' \
    --header 'If-None-Match: W/"5f99c43bf6a930044b034"'

HTTP/1.1 304 Not Modified
Content-Security-Policy: sandbox allow-forms allow-scripts
Etag: W/"5f99c43bf6a930044b034"
Content-Type: application/json
Accept-Encoding: identity,gzip
Date: Tue, 25 Jul 2023 16:05:29 GMT
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Robots-Tag: noindex, nofollow, noimageindex
Vary: Accept-Encoding
X-Dropbox-Response-Origin: far_remote
X-Dropbox-Request-Id: 39f2e29e01f94a9c96bc17e8f05d98f0

This correctly returns 304 Not Modified and avoids downloading the content which has not changed.

How can I do this using Dropbox API v2? The only way I can think of is to make two calls:

  • Call GetMetadataAsync to get the rev property.
  • Compare this to my stored eTag to see if the rev has changed.
  • If changed, call DownloadAsync to get the new contents.

But the whole point of If-None-Match is to avoid making two calls!

I could use the HttpClient directly and set If-None-Match in the request header myself, but this means I will not get the automatic refreshing of the access token which takes place in DropboxRequestHandler.

Thanks.

@greg-db
Copy link
Contributor

greg-db commented Jul 25, 2023

Thanks for writing this up! You have this correct, the Dropbox .NET SDK doesn't currently support setting If-None-Match unfortunately, so you'd need to make the multiple calls, which would be less efficient. I'll pass this along as a feature request, but I can't promise if or when that might be implemented.

By the way, if you haven't already, check out the Detecting Changes Guide, which covers some other strategies for following changes relatively efficiently which might be helpful, depending on your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants