-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,7 @@ public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext c | |
HashSet<RequestListener> requestListeners = new HashSet<>(); | ||
requestListeners.add(new SystraceRequestListener()); | ||
|
||
OkHttpClient client = OkHttpClientProvider.createClient(); | ||
OkHttpClient client = new OkHttpClientProvider().get(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
thotegowda
Author
Owner
|
||
|
||
// make sure to forward cookies for any requests via the okHttpClient | ||
// so that image requests to endpoints that use cookies still work | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.modules.network; | ||
|
||
import android.os.Build; | ||
|
||
import com.facebook.common.logging.FLog; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import okhttp3.ConnectionSpec; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.TlsVersion; | ||
|
||
public class DefaultOkHttpProvider implements OkHttpClientProvider { | ||
|
||
public OkHttpClient get() { | ||
// No timeouts by default | ||
OkHttpClient.Builder client = new OkHttpClient.Builder() | ||
.connectTimeout(0, TimeUnit.MILLISECONDS) | ||
.readTimeout(0, TimeUnit.MILLISECONDS) | ||
.writeTimeout(0, TimeUnit.MILLISECONDS) | ||
.cookieJar(new ReactCookieJarContainer()); | ||
|
||
return enableTls12OnPreLollipop(client).build(); | ||
} | ||
|
||
/* | ||
On Android 4.1-4.4 (API level 16 to 19) TLS 1.1 and 1.2 are | ||
available but not enabled by default. The following method | ||
enables it. | ||
*/ | ||
public static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { | ||
try { | ||
client.sslSocketFactory(new TLSSocketFactory()); | ||
|
||
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) | ||
.tlsVersions(TlsVersion.TLS_1_2) | ||
.build(); | ||
|
||
List<ConnectionSpec> specs = new ArrayList<>(); | ||
specs.add(cs); | ||
specs.add(ConnectionSpec.COMPATIBLE_TLS); | ||
specs.add(ConnectionSpec.CLEARTEXT); | ||
|
||
client.connectionSpecs(specs); | ||
} catch (Exception exc) { | ||
FLog.e("OkHttpClientProvider", "Error while enabling TLS 1.2", exc); | ||
} | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
autovalue
|
||
|
||
return client; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,31 +10,44 @@ | |
package com.facebook.react.shell; | ||
|
||
import com.facebook.imagepipeline.core.ImagePipelineConfig; | ||
import com.facebook.react.modules.network.OkHttpClientProvider; | ||
|
||
/** | ||
* Configuration for {@link MainReactPackage} | ||
*/ | ||
public class MainPackageConfig { | ||
|
||
private ImagePipelineConfig mFrescoConfig; | ||
private final OkHttpClientProvider okHttpClientProvider; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mkonicek
|
||
private final ImagePipelineConfig mFrescoConfig; | ||
|
||
private MainPackageConfig(Builder builder) { | ||
mFrescoConfig = builder.mFrescoConfig; | ||
okHttpClientProvider = builder.okHttpClientProvider; | ||
} | ||
|
||
public ImagePipelineConfig getFrescoConfig() { | ||
return mFrescoConfig; | ||
} | ||
|
||
public OkHttpClientProvider getOkHttpClientProvider() { | ||
return okHttpClientProvider; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private ImagePipelineConfig mFrescoConfig; | ||
private OkHttpClientProvider okHttpClientProvider; | ||
|
||
public Builder setFrescoConfig(ImagePipelineConfig frescoConfig) { | ||
public Builder withFrescoConfig(ImagePipelineConfig frescoConfig) { | ||
mFrescoConfig = frescoConfig; | ||
return this; | ||
} | ||
|
||
public Builder withOkHttpClientProvider(OkHttpClientProvider okHttpClientProvider) { | ||
this.okHttpClientProvider = okHttpClientProvider; | ||
return this; | ||
} | ||
|
||
public MainPackageConfig build() { | ||
return new MainPackageConfig(this); | ||
} | ||
|
8 comments
on commit b9aaf77
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, I'm not the right person for reviewing this. I'll ping this commit internally to see if any RN Android people want to jump on it - but your best bet is probably taking this through the normal PR process.
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.
Could you please create a PR with a lot of context explaining what issue this is solving?
What is the use case for having a different OkHttp "provider"? What would anyone want to do that What is a provider? This has probably been discussed before elsewhere (?) but I have no context unfortunately.
Creating a pull request explaining why and how anyone would use this code would be a good start to make it possible for the people on the React Native team to review this (I'm not on that team anymore but can help review).
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.
Or is the purpose of this commit solely to enable TLS on Android 4.1-4.4 (API level 16 to 19)?
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.
@mkonicek - Thanks for looking at this.
The main purpose of this commit is to make brown-field applications inject their existing OKHtttpClient
instance to react-native networking system. This will enable them to use fetch
in javascript and still re-use their existing networking infrastructure (like headers, interceptors, logging, fallbacks, error handling etc) of their existing application, instead of bridging themselves.
I have made few more changes on this. Will send a PR with all the details.
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.
Makes sense, thank s for the explanation @thotegowda! From a quick look the idea looks fine, please send the pull request. Added some inline comments.
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.
Working on comments as well as test. Will submit PR in a day or two
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 do you have a PR?
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.
@mkonicek Thank you very much for your feedback. I have incorporated them and submitted a PR. Please review this facebook#14068
What does
new OkHttpClientProvider().get()
do compared toOkHttpClientProvider.createClient()
? Are you changing this because you want Fresco to use the custom OkHttp client?