dropbox / dropbox/dropbox-sdk-dotnet

How to use eTags

Open
#358 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
347
Forks
439
Avg merge
4m
Merged PRs (30d)
11

Description

According to the [Dropbox for HTTP Developers](https://www.dropbox.com/developers/documentation/http/documentation) 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](https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Response-headers/td-p/219273), 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](https://github.com/dropbox/dropbox-sdk-dotnet/blob/fde57457076c586fea4b371952b6c31635670c84/dropbox-sdk-dotnet/Dropbox.Api/DropboxRequestHandler.cs#L370).

Thanks.

Contributor guide

Open the contributing guide

Research direction

Start with Dropbox.Api/DropboxRequestHandler.cs around the referenced token-refresh logic, then trace how DownloadAsync constructs and sends its request. Determine whether the SDK can expose or preserve If-None-Match while retaining automatic token refresh; done requires a documented, supported way to receive a 304 response without an extra metadata call.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.