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
ETag and If-None-Match #831
Comments
What happens if you add this header to your server's response:
My guess is that OkHttp will do the right thing if it knows the response content changes with the |
Got a similar issue. If I do a manual ETag implementation, saving eTag to preferences cache and adding it as a header to every appropriate request - I get 304 from the server (and Retrofit throws a RetrofitError, not thinking it as a successful response, btw). Looks like a somewhat correct behavior. With Cache set as in example, I see that Retrofit is hitting CONDITIONAL CACHE 200, but I don't see "If-None-Match" set to my request in logs, and with the time it takes for request, I assume that even though Retorift hits the cache, it still did a full request to the server, and server had responded not with 304, but with full set of data - it takes too long. How can I be sure that 'If-None-Match' header is correctly set? Shouldn't it be displayed in logs when setLogLevel(RestAdapter.LogLevel.FULL) is set? |
Actually |
I don't use Session header at all and doubt our server uses it too. |
How to add If-None-Match on okhttp ? |
@crossle sounds like a question for stack overflow. |
@swankjesse okhttp auto support If-None-Match and ETag? @swankjesse http://stackoverflow.com/questions/27751634/okhttp-add-etag-and-if-none-match |
I'll reference my question here |
The server return a ETag, but retrofit full log not show ETag header, use curl -I print |
@swankjesse if server return |
It will cache, but it has to make a request back to the server when you
|
@JakeWharton, could you please give us some more information about tying together OkHttp Inteceptors with Retrofit? @swankjesse have mentioned downloading a pre-release snapshot and said a release that supports that is planned to be released soon. When can we expect it? |
We don't give ETAs. It could be anywhere from tomorrow up to 4-6 weeks.
|
I see, thanks. |
Yup, building it yourself works. |
I test use |
Because Retrofit only sees the 200. OkHttp sees the 304.
|
@JakeWharton Thank you! |
Bad news, I used retrofit 1.9, okhttp 2.2, use intercepter log, no |
Did you use |
use |
That is above the cache, you'll always get 200s. |
Hey @JakeWharton. |
Try networkInteceptors, same problem. |
@JakeWharton How about this? same problem use networkInteceptors, no ETag. |
Guys, any update on this matter? |
Can you paste the network interceptors log for two calls to the same URL, with a cache installed? I wanna read the headers myself! |
====== clean install, initial request =======
====== same app instance, second request =======
====== application restart, first request =======
|
I will give example from a different server that doesn't gzip once I make sure it really works manually. Asked a server dev to check everything. The example provided works manually and sends 304 with |
Same problem. |
When you read the response, are you calling close() when you're done? |
Where should I call it? Isn't retrofit responsible on this stuff? |
Any other ideas, guys? I need this Etag working finally. |
Put a breakpoint in the |
You keep mentioning this 'close()' method, but I don't get which class it this method from and where should I call it. HttpEngine.cacheWritingResponse() - that's probably in okHttp source, I don't yet have it added to the project as a source, so if nothing will work - I'll try this out. Here's my JacksonConverter implementation: I'll try closing TypedInput.in(), just in case this is the correct thing to do, but basically implementation was grabbed from here: http://kdubblabs.com/java/retrofit-by-square/retrofit-using-jackson-json-conversion/ |
The Jackson converter was contributed. I'll note the Gson converter does On Wed Jan 28 2015 at 1:41:31 PM AAverin notifications@github.com wrote:
|
Thanks, Jake. |
Yes. Per its documentation it always calls close on the underlying reader. On Wed Jan 28 2015 at 1:47:27 PM AAverin notifications@github.com wrote:
|
Looks like closing TypedInput.in() doesn't resolve the issue. At least I still don't see 'If-None-Match' header being sent with a request by OkHttp.
|
@AAverin can you share the URL that's impacted? I'd like to figure out if this is OkHttp misbehaving, your server, or something else. If you don't want to share it here, I'm jesse at swank.ca. |
When passing If-None-Match manually to my server - everything works correctly. |
Looks like the bug is we're sending both |
Great, thanks. |
When release include this issue fix? |
February. |
@swankjesse When release include this issue fix? |
The plan is to do 2.3 in March, but no promises. |
Maybe publish 2.2.1? |
You can use 2.3.0-SNAPSHOT for now.
|
I have troubles with the ETag-based caching. I am using OkHttp 1.5.4 and Retrofit 1.5.1 with
HttpResponseCache
set. There are logs below for better explanation.The request with the
Session
header set to a token A. OkHttp hits the network, which is great.The second request with the
Session
header set to a token A. OkHttp hits the cache, which is great as well.The third request with the
Session
header set to token B. OkHttp hits the cache again, which is not so great, because in this case the server returns a different response with a different ETag actually.Personally I expect to see the
If-None-Match
at the second and the third requests. Is the issue related to the lack ofCache-Control
header at servers’s responses? Maybe I just don’t understand the caching strategy properly.The text was updated successfully, but these errors were encountered: