-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Documentation about proposed RCTSetCustomNSURLSessionConfigurationProvider #2629
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
Documentation about proposed RCTSetCustomNSURLSessionConfigurationProvider #2629
Conversation
|
✔️ Deploy Preview for react-native ready! 🔨 Explore the source changes: 58f1b9f 🔍 Inspect the deploy log: https://app.netlify.com/sites/react-native/deploys/611228ed5f74f50007ccaf93 😎 Browse the preview: https://deploy-preview-2629--react-native.netlify.app |
Simek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hakonk, thank you for the companion PR for the docs! 👍
However you have edited the docs for 0.64 release, when the changes should be part of next version:
Please move the new section to the suggested file above and then PR should be ready to be merged after the 0.65 release. 🙂
|
Hi @Simek ! I have moved the comment now 🙂 |
Simek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hakonk Thank you for the update! 👍
|
@hakonk If you don't mind, after applying the patch with diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
index 75b84eb..5a91bd0 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
@@ -8,6 +8,11 @@
#import <React/RCTInvalidating.h>
#import <React/RCTURLRequestHandler.h>
+typedef NSURLSessionConfiguration* (^NSURLSessionConfigurationProvider)(void);
+/**
+ * The block provided via this function will provide the NSURLSessionConfiguration for all HTTP requests made by the app.
+*/
+RCT_EXTERN void RCTSetCustomNSURLSessionConfigurationProvider(NSURLSessionConfigurationProvider);
/**
* This is the default RCTURLRequestHandler implementation for HTTP requests.
*/
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index 274f381..b500f5a 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -18,6 +18,12 @@
@end
+static NSURLSessionConfigurationProvider urlSessionConfigurationProvider;
+
+void RCTSetCustomNSURLSessionConfigurationProvider(NSURLSessionConfigurationProvider provider) {
+ urlSessionConfigurationProvider = provider;
+}
+
@implementation RCTHTTPRequestHandler
{
NSMapTable *_delegates;
@@ -75,14 +81,20 @@ RCT_EXPORT_MODULE()
NSOperationQueue *callbackQueue = [NSOperationQueue new];
callbackQueue.maxConcurrentOperationCount = 1;
callbackQueue.underlyingQueue = [[_bridge networking] methodQueue];
- NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
- // Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
- if (useWifiOnly) {
- configuration.allowsCellularAccess = ![useWifiOnly boolValue];
+ NSURLSessionConfiguration *configuration;
+ if (urlSessionConfigurationProvider) {
+ configuration = urlSessionConfigurationProvider();
+ } else {
+ configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
+ // Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
+ if (useWifiOnly) {
+ configuration.allowsCellularAccess = ![useWifiOnly boolValue];
+ }
+ [configuration setHTTPShouldSetCookies:YES];
+ [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
+ [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
}
- [configuration setHTTPShouldSetCookies:YES];
- [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
- [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
+ assert(configuration != nil);
_session = [NSURLSession sessionWithConfiguration:configuration
delegate:self
delegateQueue:callbackQueue];Should I be able to use the example in this PR after a simple As of right now, adding |
|
Hi, @taylorkline! I believe the correct import should be |
|
Thank you! |
|
@hakonk the |
|
I willing to contribute, however, I'm unsure what kind of branching strategy you find appropriate to achieve this. |
|
All the "versioned" docs are located under This is how the Docusaurus works, we do not use separate branches for the docs releases to keep it simple and to allow an easy editing or backporting in the older docs. 🙂 |
This PR contains documentation for the proposed changes in this PR facebook/react-native#27701.