download(_:willSend:redirectResponse:)
Sent when the download object determines that it must change URLs in order to continue loading a request.
Declaration
optional func download(_ download: NSURLDownload, willSend request: URLRequest, redirectResponse: URLResponse?) -> URLRequest?Parameters
- download:
The URL download object sending the message.
- request:
The proposed redirected request. The delegate should inspect the redirected request to verify that it meets its needs, and create a copy with new attributes to return to the connection if necessary.
- redirectResponse:
The URL response that caused the redirect. May be
nilin cases where this method is not being sent as a result of involving the delegate in redirect processing.
Return Value
The actual URL request to use in light of the redirection response. The delegate may copy and modify request as necessary to change its attributes, return request unmodified, or return nil.
Discussion
If the delegate wishes to cancel the redirect, it should call the download object’s cancel() method. Alternatively, the delegate method can return nil to cancel the redirect, and the download will continue to process. This has special relevance in the case where redirectResponse is not nil. In this case, any data that is loaded for the download will be sent to the delegate, and the delegate will receive a downloadDidFinish(_:) or download(_:didFailWithError:) message, as appropriate.
Special Considerations
The delegate can receive this message as a result of transforming a request’s URL to its canonical form, or for protocol-specific reasons, such as an HTTP redirect. The delegate implementation should be prepared to receive this message multiple times.