Should a custom NSURLProtocol follow redirects itself, or let its client worry about that?
Asked Answered
K

1

10

The NSURLProtocolClient protocol includes a method, -URLProtocol:wasRedirectedToRequest:redirectResponse:, which instances of NSURLProtocol subclasses are supposed to use to tell an URL protocol client that the request was redirected. However, I'm not sure whether the URL Protocol is then supposed to attempt to retrieve the resource from the redirected URL or let the client issue a new request for that resource.

Can anyone tell me what the original URL protocol object is supposed to do in the case of a redirect?

Kerstinkerwin answered 18/4, 2012 at 17:43 Comment(0)
K
3

To answer this question, I simply removed the code in my URL protocol implementation that follows the link given in the redirect response. It should be pretty obvious if the connection client follows creates a new connection to load the new URL. As it turns out, nothing happened -- the client never creates a new connection, and the redirect isn't followed. From this I have to conclude that the URL protocol itself should attempt to load URL given in the redirect response.

Kerstinkerwin answered 20/4, 2012 at 1:39 Comment(2)
I am trying to implement my own URL protocol and in it, I want to load the redirected url automatically in the protocol and send it over to the url loading system. Is it sufficient to change URL: key to the redirected URL in the response or do I need to do anything more?Informed
Thanks for figuring this out. None of the NSURLProtocol tutorials I've seen mention handling redirects.Imperishable

© 2022 - 2024 — McMap. All rights reserved.