If-No-Match and NSURLConnection

My server sets the etag header element to support caching.

IOS application (6.1.4) uses its own NSURLConnection class to send an XML request to the server

The first time the server sends a response with the etag setting in the header

If the iOS application sends the exact same request to the server, I can see in the server logs that the if-none-match header is not populated by NSURLConnection

... and then the server responds 200 instead of 304

The cache policy used for the request:

[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 myself? (getting a response from the cache, reading the etag value and setting in the request header)?

+7
source share
2 answers

I ran into this problem. For me, I used the default cache policy (NSURLRequestUseProtocolCachePolicy), and it automatically set the "if-none-match" header field that the server would check. However, setting the cache policy as "NSURLRequestReloadIgnoringLocalCacheData" obviously deleted this header field.

Have you tried other cache policy values ​​to see if they added this header for you?

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

edit . I found another question that confirms the above: NSURLCache and ETags

+1
source

Also find the characters in Xcode (right-click on the character and "Go to Definition"). There are some that are present but not implemented, according to the comments of the file!

0
source

All Articles