mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 19:44:13 +00:00
Fix cookies not being sent with <Image> network requests
Reviewed By: pvulgaris Differential Revision: D4669967 fbshipit-source-id: d26da8d3a60f71cf3751eb1c73974b0e57e59bed
This commit is contained in:
parent
231bf7c68b
commit
d2796ea4ed
@ -19,6 +19,7 @@ android_library(
|
||||
react_native_dep("third-party/android/support-annotations:android-support-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_dep("third-party/java/okhttp:okhttp3"),
|
||||
react_native_dep("third-party/java/okhttp:okhttp3-urlconnection"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/common:common"),
|
||||
react_native_target("java/com/facebook/react/module/annotations:annotations"),
|
||||
|
@ -14,20 +14,24 @@ import java.util.HashSet;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.facebook.common.soloader.SoLoaderShim;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.common.soloader.SoLoaderShim;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory;
|
||||
import com.facebook.imagepipeline.core.ImagePipelineConfig;
|
||||
import com.facebook.imagepipeline.listener.RequestListener;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.modules.common.ModuleDataCleaner;
|
||||
import com.facebook.react.modules.network.CookieJarContainer;
|
||||
import com.facebook.react.modules.network.ForwardingCookieHandler;
|
||||
import com.facebook.react.modules.network.OkHttpClientProvider;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import okhttp3.JavaNetCookieJar;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
/**
|
||||
@ -112,7 +116,7 @@ public class FrescoModule extends ReactContextBaseJavaModule implements
|
||||
return sHasBeenInitialized;
|
||||
}
|
||||
|
||||
private static ImagePipelineConfig getDefaultConfig(Context context) {
|
||||
private static ImagePipelineConfig getDefaultConfig(ReactContext context) {
|
||||
return getDefaultConfigBuilder(context).build();
|
||||
}
|
||||
|
||||
@ -122,14 +126,21 @@ public class FrescoModule extends ReactContextBaseJavaModule implements
|
||||
*
|
||||
* @return {@link ImagePipelineConfig.Builder} that has been initialized with default values
|
||||
*/
|
||||
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(Context context) {
|
||||
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) {
|
||||
HashSet<RequestListener> requestListeners = new HashSet<>();
|
||||
requestListeners.add(new SystraceRequestListener());
|
||||
|
||||
OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient();
|
||||
OkHttpClient client = OkHttpClientProvider.createClient();
|
||||
|
||||
// make sure to forward cookies for any requests via the okHttpClient
|
||||
// so that image requests to endpoints that use cookies still work
|
||||
CookieJarContainer container = (CookieJarContainer) client.cookieJar();
|
||||
ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
|
||||
container.setCookieJar(new JavaNetCookieJar(handler));
|
||||
|
||||
return OkHttpImagePipelineConfigFactory
|
||||
.newBuilder(context.getApplicationContext(), okHttpClient)
|
||||
.setNetworkFetcher(new ReactOkHttpNetworkFetcher(okHttpClient))
|
||||
.newBuilder(context.getApplicationContext(), client)
|
||||
.setNetworkFetcher(new ReactOkHttpNetworkFetcher(client))
|
||||
.setDownsampleEnabled(false)
|
||||
.setRequestListeners(requestListeners);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user