Remove cookie handler on destroy

Reviewed By: andreicoman11, astreet

Differential Revision: D2690634

fb-gh-sync-id: a2ab8ce52dd501eed88f166b4c218886ea229744
This commit is contained in:
Alexander Blom 2015-11-24 09:46:45 -08:00 коммит произвёл facebook-github-bot-7
Родитель 9d333e6411
Коммит 3a00545bc7
3 изменённых файлов: 13 добавлений и 24 удалений

Просмотреть файл

@ -80,8 +80,7 @@ public class FrescoModule extends ReactContextBaseJavaModule implements
}
Context context = this.getReactApplicationContext().getApplicationContext();
OkHttpClient okHttpClient =
OkHttpClientProvider.getCookieAwareOkHttpClient(getReactApplicationContext());
OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient();
ImagePipelineConfig.Builder builder =
OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient);

Просмотреть файл

@ -14,7 +14,6 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.CookieHandler;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.GuardedAsyncTask;
@ -58,6 +57,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
private static final int CHUNK_TIMEOUT_NS = 100 * 1000000; // 100ms
private final OkHttpClient mClient;
private final ForwardingCookieHandler mCookieHandler;
private final @Nullable String mDefaultUserAgent;
private boolean mShuttingDown;
@ -68,6 +68,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
super(reactContext);
mClient = client;
mClient.networkInterceptors().add(new StethoInterceptor());
mCookieHandler = new ForwardingCookieHandler(reactContext);
mShuttingDown = false;
mDefaultUserAgent = defaultUserAgent;
}
@ -76,7 +77,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
* @param context the ReactContext of the application
*/
public NetworkingModule(final ReactApplicationContext context) {
this(context, null, OkHttpClientProvider.getCookieAwareOkHttpClient(context));
this(context, null, OkHttpClientProvider.getOkHttpClient());
}
/**
@ -85,13 +86,18 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
* caller does not provide one explicitly
*/
public NetworkingModule(ReactApplicationContext context, String defaultUserAgent) {
this(context, defaultUserAgent, OkHttpClientProvider.getCookieAwareOkHttpClient(context));
this(context, defaultUserAgent, OkHttpClientProvider.getOkHttpClient());
}
public NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client) {
this(reactContext, null, client);
}
@Override
public void initialize() {
mClient.setCookieHandler(mCookieHandler);
}
@Override
public String getName() {
return "RCTNetworking";
@ -102,10 +108,8 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
mShuttingDown = true;
mClient.cancel(null);
CookieHandler cookieHandler = mClient.getCookieHandler();
if (cookieHandler instanceof ForwardingCookieHandler) {
((ForwardingCookieHandler) cookieHandler).destroy();
}
mCookieHandler.destroy();
mClient.setCookieHandler(null);
}
@ReactMethod
@ -319,10 +323,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
@ReactMethod
public void clearCookies(com.facebook.react.bridge.Callback callback) {
CookieHandler cookieHandler = mClient.getCookieHandler();
if (cookieHandler instanceof ForwardingCookieHandler) {
((ForwardingCookieHandler) cookieHandler).clearCookies(callback);
}
mCookieHandler.clearCookies(callback);
}
private @Nullable MultipartBuilder constructMultipartBody(

Просмотреть файл

@ -13,8 +13,6 @@ import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
import com.facebook.react.bridge.ReactContext;
import com.squareup.okhttp.OkHttpClient;
/**
@ -25,7 +23,6 @@ public class OkHttpClientProvider {
// Centralized OkHttpClient for all networking requests.
private static @Nullable OkHttpClient sClient;
private static ForwardingCookieHandler sCookieHandler;
public static OkHttpClient getOkHttpClient() {
if (sClient == null) {
@ -34,14 +31,6 @@ public class OkHttpClientProvider {
return sClient;
}
public static OkHttpClient getCookieAwareOkHttpClient(ReactContext context) {
if (sCookieHandler == null) {
sCookieHandler = new ForwardingCookieHandler(context);
getOkHttpClient().setCookieHandler(sCookieHandler);
}
return getOkHttpClient();
}
private static OkHttpClient createClient() {
// TODO: #7108751 plug in stetho
OkHttpClient client = new OkHttpClient();