-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
No easy mechanism for getting/providing an ETag #86
Comments
Interesting note... while investigating this issue, I discovered that several APIs already expose the Etag information to the caller. For example, this already exists in storage:v1, drive:v2, and calendar:v3. Now investigating how to support the If-None-Match and If-Match. |
@imjasonh please take a look at https://code-review.googlesource.com/2970 |
Thanks for the quick reply! The change looks like it covers the conditional IsError is a nice addition too! :)
|
Thanks, @imjasonh . Check out my comment above... I believe all the APIs of interest already return the Etag values. Do a grep on "Etag" over all the APIs, and you will see a lot. |
Ah, I see what you're saying. But then it's on each API provider to pass
|
I actually did perform some testing on the Calendar and Storage APIs, and could not find any Etags passed in the header, but then stumbled across the Etags within the API responses themselves. |
Ah! So compute:v1 is one of the APIs that doesn't provide an explicit Etag in the response struct but instead leaves it in the header. OK, I'll see what I can do. Thanks for the example. |
Wow, this could potentially really mess up the |
Yeah, I agree it's kind of a big change. So far the client hasn't exposed It's not just that API, or even just Compute; every API would need to add Is there any other way to introspect into the raw HTTP response? Maybe I
|
I suppose we could add a DoWithHeader() that returns 3 values... the response, the header, and an error. I would have to get @bradfitz approval for that. (Do() would call DoWithHeader() and just return the response and error like it currently does.) Brad, thoughts? |
@imjasonh - I've gone ahead and implemented |
That change looks good to me, thanks for putting it together. Two small questions:
But this looks fine to me if it passes Brad's muster. Thanks again! |
Re#1 - good point... I will switch it. Re#2 - returning the full response seems much riskier to me because of the closed Body. Let me fix the first point then I will send it out to Brad for review and let's see what he says about the second point. |
Thanks Glenn! 👍 |
You're welcome, Jason! |
Here's my use case: I start a compute instance with
svc.Instances.Insert(...).Do()
which returns anOperation
resource. I want to periodically poll on this operation to determine whether it's updated, but I don't really care to receive the whole resource each time I poll, and I know that Google APIs support theIf-None-Match
header to trigger an HTTP304 Not Modified
response and avoid sending the resource again.This is just an example; I may be polling the contents of a folder in Drive, or events in a Calendar, or really anything that can change its state. If I don't care about the resource and just want to know whether it's changed, I should use an ETag.
In generated clients, there's no way to get the ETag from a previous request, and no way to provide one in the headers of subsequent requests. The APIs Explorer shows that at least the ETag response header is sent in the response, so it's available, just not exposed in any way via the generated clients.
More info:
The text was updated successfully, but these errors were encountered: