-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[iOS] Custom NSURLSession configuration #27701
[iOS] Custom NSURLSession configuration #27701
Conversation
…tHandler to allow for configuring the NSURLSession. Add code that is commented out in AppDelegate for testing different configurations
Hi hakonk! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
+1 On this, this will greatly simplify implementations that need to use their own NSURLSessionConfiguration, ex. RCTCronetHTTPRequestHandler.mm |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Any movement on this? I am looking for the ability to customize the iOS networking client like you do on Android. |
Base commit: 286fac5 |
Base commit: 286fac5 |
@zsiegel I haven't heard from the review team. I assume they've had their hands full. Not sure if I should tag someone in the discussion, and in that case, who. |
Hi @hakonk thanks for the PR, I'll see if I can ping someone for this. |
Thanks, @safaiyeh 😊 |
Hey @safaiyeh, did you have any luck finding anyone? |
Hi @TheSavior, could someone check this out? |
Nearly a year already.. |
Happy new year! I guess there are more important PRs in the pipe still. Any news @safaiyeh ? |
Interesting that this important (for SSL Pinning that can't use sizzling) PR is still not merged. |
@@ -82,6 +82,12 @@ @implementation AppDelegate | |||
- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |||
{ | |||
RCTEnableTurboModule(YES); | |||
// uncomment to configure NSURLSession |
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.
We probably don’t need to add commented code here as this is an uncommon use case. Perhaps this explanation of usage should just live in the documentation.
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.
Alright, I can add a section about that. Would it be appropriate to add a section here for instance?
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.
I think so
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.
I have created a PR that contains the needed documentation now: facebook/react-native-website#2629
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.
Also, the commented code has been removed in: 1634c87
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.
@TheSavior Please see messages above 🙂
@sshic has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Moved example code to PR in RN documentation website
@JoshuaGross has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@JoshuaGross merged this pull request in 58444c7. |
Summary: While it is possible in the React Native implementation for Android to provide a custom configuration for HTTP requests, the iOS implementation does not allow for the same customization. As the NSURLSession used for HTTP requests on iOS is configured internally, one may for instance not supply an ephemeral configuration for HTTP requests. Other concerns related to the given problem have been addressed in the community: react-native-community/discussions-and-proposals#166. I did make a PR with an RFC in the community repo, but after some discussion in the said repo, I figured I might as well make a PR with a suggestion :) ## Changelog [iOS] [Added] - Allow for configuring the NSURLSessionConfiguration Implement a C function `RCTSetCustomNSURLSessionConfigurationProvider` which gives the app programmer the ability to provide a block which provides an NSURLSessionConfiguration that will be used for all HTTP requests instead of the default configuration. The provided block will be called when the session configuration is needed. Pull Request resolved: facebook#27701 Test Plan: Unsure if this can be tested in any other way than uncommenting the example code in `RNTester/RNTester/AppDelegate.mm`. Reviewed By: yungsters Differential Revision: D28680384 Pulled By: JoshuaGross fbshipit-source-id: ae24399955581a1cc9f4202f0f6f497bfe067a5c
Summary: While it is possible in the React Native implementation for Android to provide a custom configuration for HTTP requests, the iOS implementation does not allow for the same customization. As the NSURLSession used for HTTP requests on iOS is configured internally, one may for instance not supply an ephemeral configuration for HTTP requests. Other concerns related to the given problem have been addressed in the community: react-native-community/discussions-and-proposals#166. I did make a PR with an RFC in the community repo, but after some discussion in the said repo, I figured I might as well make a PR with a suggestion :) ## Changelog [iOS] [Added] - Allow for configuring the NSURLSessionConfiguration Implement a C function `RCTSetCustomNSURLSessionConfigurationProvider` which gives the app programmer the ability to provide a block which provides an NSURLSessionConfiguration that will be used for all HTTP requests instead of the default configuration. The provided block will be called when the session configuration is needed. Pull Request resolved: #27701 Test Plan: Unsure if this can be tested in any other way than uncommenting the example code in `RNTester/RNTester/AppDelegate.mm`. Reviewed By: yungsters Differential Revision: D28680384 Pulled By: JoshuaGross fbshipit-source-id: ae24399955581a1cc9f4202f0f6f497bfe067a5c
Summary: While it is possible in the React Native implementation for Android to provide a custom configuration for HTTP requests, the iOS implementation does not allow for the same customization. As the NSURLSession used for HTTP requests on iOS is configured internally, one may for instance not supply an ephemeral configuration for HTTP requests. Other concerns related to the given problem have been addressed in the community: react-native-community/discussions-and-proposals#166. I did make a PR with an RFC in the community repo, but after some discussion in the said repo, I figured I might as well make a PR with a suggestion :) ## Changelog [iOS] [Added] - Allow for configuring the NSURLSessionConfiguration Implement a C function `RCTSetCustomNSURLSessionConfigurationProvider` which gives the app programmer the ability to provide a block which provides an NSURLSessionConfiguration that will be used for all HTTP requests instead of the default configuration. The provided block will be called when the session configuration is needed. Pull Request resolved: facebook#27701 Test Plan: Unsure if this can be tested in any other way than uncommenting the example code in `RNTester/RNTester/AppDelegate.mm`. Reviewed By: yungsters Differential Revision: D28680384 Pulled By: JoshuaGross fbshipit-source-id: ae24399955581a1cc9f4202f0f6f497bfe067a5c
@pke you mentioned this is useful for SSL pinning. Can you elaborate on how? From what I can tell, Apple's docs on performing manual server trust authentication state that we should provide an This PR does not allow us to set our own @hakonk definitely open to your input as well. Thank you for this PR. |
@taylorkline I believe you are right in that you would have to implement You can make use of swizzling when you do not have the means to implement |
@hakonk Thank you for confirming and thank you for your time. |
@taylorkline iirc one can only sizzle functions once. So if one react native module sizzles the NSURLSession (for certificate pinning) then no other module could sizzle the session. The ability to provide the pinning configuration for the sessions directly removes the need to use sizzling for it. So thanks for merging this! |
Is this in v0.65.0? The commit does not appear to be tagged with v0.65.0. |
0.65 was cut on April 28th, before this PR was merged. This PR will be included in 0.66 |
@TheSavior I'm a bit confused. The changelog for 0.65.0 lists this PR. |
Ah, I was looking at the tags on the commit as @taylorkline mentioned. It looks like this commit was cherry picked and thus doesn't have the same hash in the release branch. This commit is in 0.65.0 here: c299694 Sorry for the confusion! 😅 |
Alright, thanks for answering so quickly! 😄 |
Summary
While it is possible in the React Native implementation for Android to provide a custom configuration for HTTP requests, the iOS implementation does not allow for the same customization. As the NSURLSession used for HTTP requests on iOS is configured internally, one may for instance not supply an ephemeral configuration for HTTP requests. Other concerns related to the given problem have been addressed in the community: react-native-community/discussions-and-proposals#166. I did make a PR with an RFC in the community repo, but after some discussion in the said repo, I figured I might as well make a PR with a suggestion :)
Changelog
[iOS] [Added] - Allow for configuring the NSURLSessionConfiguration
Implement a C function
RCTSetCustomNSURLSessionConfigurationProvider
which gives the app programmer the ability to provide a block which provides an NSURLSessionConfiguration that will be used for all HTTP requests instead of the default configuration. The provided block will be called when the session configuration is needed.Test Plan
Unsure if this can be tested in any other way than uncommenting the example code in
RNTester/RNTester/AppDelegate.mm
.