<!--
{
  "availability" : [
    "macOS: 10.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLDownloadDelegate/download(_:willSend:redirectResponse:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLDownloadDelegate(im)download:willSendRequest:redirectResponse:"
  },
  "title" : "download(_:willSend:redirectResponse:)"
}
-->

# download(_:willSend:redirectResponse:)

Sent when the download object determines that it must change URLs in order to continue loading a request.

```
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 `nil` in 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()`](/documentation/Foundation/NSURLDownload/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(_:)`](/documentation/Foundation/NSURLDownloadDelegate/downloadDidFinish(_:)) or [`download(_:didFailWithError:)`](/documentation/Foundation/NSURLDownloadDelegate/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)