Greetings,
I would like to understand this URLCache behavior for two different requests to the same end point but with a different header value. Here is a code with comment explaining the behavior.
// Create a request to for a url.
let url = URL(string: "https://<my url>?f=json")!
var request = URLRequest(url: url)
// Set custom header with a value.
request.setValue("myvalue", forHTTPHeaderField: "CustomField")
// Send request to get the response.
let (data, response) = try await URLSession.shared.data(for: request)
print("data: \(String(describing: String(data: data, encoding: .utf8)))")
print("response: \(response)")
// Create second request to the same url but with different value of custom header field.
var request2 = URLRequest(url: url)
request2.setValue("newvalue", forHTTPHeaderField: "CustomField")
// Check the URL cache for second request and it returns the response
// of the first request even though the second request has different header value.
let cachedResponse = URLCache.shared.cachedResponse(for: request2)
print("cachedResponse: \(cachedResponse?.response)")
Is this a bug in URLCache that request headers are not matched while returning the response?
Is this an expected behavior? If yes, why?
Post
Replies
Boosts
Views
Activity
The URLCredential documentation says that “TLS credentials are never stored permanently by URLCredentialStorage. In general, use for-session persistence for TLS credentials”.
Are there any reasons of not storing them in Keychain? Is there any security risk?
Hi All,
We have started seeing crash with iOS 14.5 for ASWebAuthenticationSession's callbackURLScheme. Is anybody seeing the issue? Is this an intentional change in iOS or a bug?
AuthenticationSession] The provided scheme is not valid. A scheme should not include special characters such as ":" or "/".** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The provided scheme is not valid. A scheme should not include special characters such as ":" or "/".'
Regards,
Nimesh
Greetings,I'm seeing an issue where URLSession incorrectly returns response from shared URLCache instead of fetching from remote. Here are the steps to reproduce issue,Steps:1. Download Xcode project from URLCacheBug.2. Open and build Xcode project. You will see the CachePolicy is set to `useProtocolCachePolicy` for URLRequest.2. Tap `Send Request 1` button which sends POST query request with parameters (specifically parameter geometry1). You will see response `Count: 5459` on the screen.3. Tap `Send Request 2` button which sends POST query request with parameters(specifically parameter geometry2). You will see response `Count: 5459` on the screen. This is the same response for request 1 and being incorrectly getting from shared URLCache4. Change the cache policy to `reloadIgnoringLocalCacheData` using segmented control.5. Tap `Send Request 1` and you will see response `Count: 5459` on the screen.6. Tap `Send Request 2` and you will see response `Count: 4672` on the screen. You can see the different response as local cache is being ignored.Here is what seems to be happening,1. First request is send and cached.2. While sending second request header `if-none-match = etag of first response` is being set as the URL of the reuest same as first one.3. Server responds with status code `304 - Not Modified`4. URLSession look for response in the URLCache and finish request with status code `200` and response from cache.5. When request cache policy is `reloadIgnoringLocalCacheData`, request is not being sent with header `if-none-match` and server responds with new and correct response.I've logged a Feedback - FB7664947 for this but wanted to know if others are noticing this as well and is there any workaround other than using different cache policy.What is the correct behavior for client and server in this scenario,1. URLRequest should not set `if-none-match` header for second request as clearly the HTTPBody is different than first request/response is in the cache?2. Server should be forgiving of header `if-none-match` and not respond with `304 - Not Modified `?I have another reproducible case where seeing this behavior and the difference between two request is just one HTTP header.Regards,Nimesh
In iOS 11, if `Settings &gt; Safari &gt; AutoFill &gt; Names and Passwords` is set to `True`, then SFSafariViewController prompts `Save This Password?` alert/actionSheet. However, dismissing the `SFSafariViewController`, dismissing the alert before user has a chance to respond to the alert. How shall I take control of the alert and dismiss the SFSafariViewController only when user has responded to an alert?Thank you!Regards,Nimesh