-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix NetworkingModule losing Cookies when multiple CatalystInstances e…
…xist and one is destroyed Differential Revision: D4451197 fbshipit-source-id: 905309f626a2295ecaa2451413e414eb827e10b0
- Loading branch information
1 parent
f4bbf1b
commit 0a71f48
Showing
2 changed files
with
4 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0a71f48
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.
Hey @olegbl , We were using OkHttpClientProvider.replaceOkHttpClient() to substitute our custom OkHttpClient (from our brown-field app) to manage interceptors, headers etc. With this commit, I don't see any way to substitute our custom OkHttpClient.
Is there any way to achieve the same?
0a71f48
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.
OkHttpClientProvider.replaceOkHttpClient() didn't go anywhere, it's still usable. It's just no longer used in NetworkingModule.
Or, do you mean that you were replacing the client inside of NetworkingModule using that? If so, I don't think there's a way right now. You'd have to extend OkHttpClientProvider or NetworkingModule to allow that sort of thing (but please don't make it use a single instance for everything as before, it would need to replace it in a way where you define how it's created rather than give it an instance.)
0a71f48
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.
Sorry for not being clear,
Before this commit, NetworkingModule would call get OkHttpClientProvider.getOkHttpClient() in the constructors, so if calling OkHttpClientProvider.replaceOkHttpClient() during app startup with custom OkHttpClient instance would result in NetworkingModule using the custom OkHttpClient instance.
But now after changing getOkHttpClient() to createClient(), this option is eliminated. Even if its set using replaceOkHttpClientI(), NetworkingModule is not going to be picked up.
I'm not able to find any way to get this working now because (1) can't extend OkHttpClientProvider, it has only static method. (2) can't extend NetworkingModule, it is final class.
Am I missing something here ?
0a71f48
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.
Yup, so it's the case I described in my second paragraph. To clarify, by "extend", I meant add new functionality and submit a PR.
0a71f48
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.
Gotcha! Thanks.
0a71f48
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.
Hello @olegbl ,
With this commit, from my module, I lost the ability to access OkHttpClient instance which is being used by RN NetworkModule provided via OkHttpClientProvider. I need this to automatically load cookies stored by RN network requests to the network requests in my module. Is there any other way to do that since this way is not working after this commit? Or maybe you will provide another one?
0a71f48
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.
@olegbl, this change breaks our stetho network inspections.
Is there no other away around this? I need a way to set the
OkHttpClient
which is being passed into theNetworkingModule
.NetworkingModule
appears to be a final class and can't be subclassed.And adding another Module to do that seems unlikely to work, and would most likely cause breaking changes if we ever need to update the react version.
What if we add an interface that allows users to provide their own
OkHttpClient
based on the context. Something similar to:0a71f48
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.
@olegbl Please check this commit, if you have time.
I took a shot at fixing this. If it looks OK, will raise a PR.
0a71f48
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.
@thotegowda, your commit looks fine to me. Good job.
Only potential blocker might be the breaking name change to
setFrescoConfig
which I personally think is acceptable since it can be easily fixed.0a71f48
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.
@codebymikey Thanks.
I'm still thinking about
setFrescoConfig
change. I had changed it as it was unused, but now wondering if its used internally by fb.0a71f48
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.
0a71f48
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.
@olegbl Please check this commit, tks.
0a71f48
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.
This is bad!
0a71f48
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.
This is also limiting the ability to certificate pin, whitelisting self-signed certs, or certificates where browser considers ok but okhttp doesnt (chain validation issue).
0a71f48
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.
An easy work around is to use reflection to modify the instance Networking module keeps. Not ideal, but solved my problem.
0a71f48
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.
@tunatoksoz Could you show a sample code for how to use reflection to modify the instance in the Networking module? Thank you!
0a71f48
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.
cropped off of my current project:
It may or may not work with some of the functionality, so use on your own risk.
0a71f48
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.
@tunatoksoz Thank you very much.
0a71f48
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.
@tunatoksoz this module works with RN v 0.49 just its need to add
StethoInterceptor