fvisticot
fvisticot

Reputation: 8536

If-None-Match and NSURLConnection

My server is setting the etag header element for caching support.

iOS (6.1.4) application is using the native NSURLConnection class to send XML request to the server

first time the server is sending the response with the etag set in the header

If the iOS app is sending exactly the same request to the server, I can see in the server logs that the if-none-match header is not filled by the NSURLConnection

... and then the server is responding with 200 instead of 304

Cache policy used for the request is:

[request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];

NSURLCache is initialized with

[[NSURLCache sharedURLCache] setMemoryCapacity:1024*1024*10];

My questions: - Is it normal that NSURLConnection did not set the "if-none-match" header field ? - Do I need to set this header field by myself ? (getting response from cache, reading the etag value and setting in in the request header) ?

Upvotes: 11

Views: 2487

Answers (2)

Anticro
Anticro

Reputation: 793

Also look up the symbols in Xcode (right-click on the symbol and "Jump to definition"). There are some that are present but unimplemented, according to the file's comments!

Upvotes: 0

johnny
johnny

Reputation: 1703

I was running into the same issue with this. For me, I was using the default cache policy (NSURLRequestUseProtocolCachePolicy) and it was automatically setting the "if-none-match" header field which the server would check for. However, setting the cache policy as "NSURLRequestReloadIgnoringLocalCacheData" obviously removed that header field.

Have you tried the other cache policy values to see if they add that header for you?

A great blog on these different cache policy values can be seen here: http://nshipster.com/nsurlcache/

edit: I found another stack overflow question that confirms what I said above: NSURLCache and ETags

Upvotes: 3

Related Questions