Skip to content
Open
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
31 changes: 31 additions & 0 deletions docs/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,37 @@ The following options are currently not working with `fetch`
* Cookie based authentication is currently unstable. You can view some of the issues raised here: https://github.com/react/react-native/issues/23185
* As a minimum on iOS, when redirected through a `302`, if a `Set-Cookie` header is present, the cookie is not set properly. Since the redirect cannot be handled manually this might cause a scenario where infinite requests occur if the redirect is the result of an expired session.

## Using OkHttp 5 on Android

Starting with React Native 0.89, you can use OkHttp 5 in your Android app by adding it to `android/app/build.gradle`:

```groovy
// android/app/build.gradle
dependencies {
implementation("com.squareup.okhttp3:okhttp:5.5.1")
}
```

If your app or one of its libraries uses `JavaNetCookieJar` or `JavaNetAuthenticator`, you will also need to add `okhttp-urlconnection` at the same version:

```groovy
// android/app/build.gradle
dependencies {
implementation("com.squareup.okhttp3:okhttp-urlconnection:5.5.1")
}
```

`react-android` depends on the OkHttp 4 version of `okhttp-urlconnection`, which React Native does not use and which does not work with OkHttp 5. If you want to remove it from your app, you can exclude it from `react-android` and from any other dependency that brings it in:

```groovy
// android/app/build.gradle
dependencies {
implementation("com.facebook.react:react-android") {
exclude group: "com.squareup.okhttp3", module: "okhttp-urlconnection"
}
}
```

## Configuring NSURLSession on iOS

For some applications it may be appropriate to provide a custom `NSURLSessionConfiguration` for the underlying `NSURLSession` that is used for network requests in a React Native application running on iOS. For instance, one may need to set a custom user agent string for all network requests coming from the app or supply `NSURLSession` with an ephemeral `NSURLSessionConfiguration`. The function `RCTSetCustomNSURLSessionConfigurationProvider` allows for such customization. Remember to add the following import to the file in which `RCTSetCustomNSURLSessionConfigurationProvider` will be called:
Expand Down