I am using latest RestKit 0.23.3
. As you likely know it works against AFNetworking 1.3.x
.
I have Team resource and obtain collection of teams from API server: I use RKObjectManager
and its -managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:
RestKit
itself works correctly for me - I do obtain teams using GET /teams
request - and I see 200 on first request and 304 on consequent requests.
However when I use exactly the same code with HEAD
requests I never receive 304
but always 200
.
I did more investigation of all this and found that after my iOS application receives first response to GET /teams
from Rails server, this response contains Etag:
, and so on subsequent requests iOS application adds "If-None-Match:"[etag code...]"
that helps Rails to make a decision to respond with 304. What I noticed is that when I use HEAD request iOS application does not mix in "If-None-Match" like it does in case of GET requests.
I tried setting all possible cache policies other than NSURLRequestUseProtocolCachePolicy
but none of these policies changed things for me.
If to request headers of HEAD /teams
I manually mix If-None-Match:"[etag code...]"
with etag obtained from HTTP log i.e. response to GET /teams
I do start getting 304 for HEAD
requests.
This makes me think that there is some problem in internals of NSURLConnection
(bug?) that prevents my iOS application from sending HEAD
with If-None-Match:
header present and correct.
I would be very thankful to anyone who can shed some light on this. Thanks.
I guess that this may be a bug inside NSURLConnection, I would also appreciate any hints on if it is possible to obtain this etag and mix it manually to my HEAD requests.
Related topic: What response should If-Modified-Since HTTP Header return if request is HEAD?
Important comment by @MikeS:
I did a quick test with straight NSURLConnection and it seems to work fine. I make a GET request, get back an ETag, and then make a HEAD request to the same URL and I can see the if-none-match header on the server side.
...
My original test was using iOS 8.0 in the simulator. I just re-tested with iOS 7.1 in the simulator and this time I did not get the if-none-match header with the HEAD request. Based on that, it does look like it's a bug in iOS 7.1, but it's fixed in iOS 8.0.