Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(background-http): Add request timeout configuration on iOS #607

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/background-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ The request object parameter has the following properties:
| `method` | `string` | The request method (e.g. `POST`). |
| `headers` | `object` | Used to specify additional headers. |
| `description` | `string` | Used to help identify the upload task locally - not sent to the remote server. |
| `timeout` | `number` | (`iOS only`) Sets the request timeout in seconds (s). |
| `utf8` | `boolean` | (`Android-only`, `multipartUpload()-only`) If true, sets the charset for the multipart request to UTF-8. Default is `false`. |
| `androidNotificationOnProgressTitle` | `string` | Use this to set the on progress title shown in the Android notifications center. |
| `androidNotificationOnProgressMessage` | `string` | Use this to set the on progress message shown in the Android notifications center. |
Expand Down
5 changes: 5 additions & 0 deletions packages/background-http/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ export interface Request {
*/
description: string;

/**
* iOS only. Sets NSMutableURLRequest.timeoutInterval value in seconds (s)
*/
timeout?: number

/**
* Use utf8 encode in requests
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/background-http/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class Session implements Session {
request.HTTPMethod = options.method;
}

if (options.timeout) {
request.timeoutInterval = options.timeout;
}

let fileURL: NSURL;
if (fileUri.substr(0, 7) === "file://") {
// File URI in string format
Expand Down