diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/BUCK index d0756896f..1e6e6d600 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/BUCK @@ -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"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java index af3c791ef..0d1a2183f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/fresco/FrescoModule.java @@ -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 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); }