Exemplo n.º 1
0
 @Override
 public void close() throws IOException {
   if (ResponseCache.getDefault() == this.delegate) {
     ResponseCache.setDefault(null);
   }
   delegate.close();
 }
Exemplo n.º 2
0
 /**
  * Returns a shallow copy of this OkHttpClient that uses the system-wide default for each field
  * that hasn't been explicitly configured.
  */
 OkHttpClient copyWithDefaults() {
   OkHttpClient result = clone();
   if (result.proxySelector == null) {
     result.proxySelector = ProxySelector.getDefault();
   }
   if (result.cookieHandler == null) {
     result.cookieHandler = CookieHandler.getDefault();
   }
   if (result.cache == null && result.cacheAdapter == null) {
     // TODO: drop support for the default response cache.
     ResponseCache defaultCache = ResponseCache.getDefault();
     result.cacheAdapter = defaultCache != null ? new CacheAdapter(defaultCache) : null;
   }
   if (result.socketFactory == null) {
     result.socketFactory = SocketFactory.getDefault();
   }
   if (result.sslSocketFactory == null) {
     result.sslSocketFactory = getDefaultSSLSocketFactory();
   }
   if (result.hostnameVerifier == null) {
     result.hostnameVerifier = OkHostnameVerifier.INSTANCE;
   }
   if (result.authenticator == null) {
     result.authenticator = AuthenticatorAdapter.INSTANCE;
   }
   if (result.connectionPool == null) {
     result.connectionPool = ConnectionPool.getDefault();
   }
   if (result.protocols == null) {
     result.protocols = Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1);
   }
   return result;
 }
Exemplo n.º 3
0
  public static HttpResponseCache install(Context context) throws IOException {
    ResponseCache installed = ResponseCache.getDefault();
    if (installed instanceof Closeable) {
      ((Closeable) installed).close();
    }

    File directory = SystemUtils.getCacheDir(context, "http");
    long maxSize =
        SystemUtils.calculateDiskCacheSize(directory, MIN_DISK_CACHE_SIZE, MAX_DISK_CACHE_SIZE);

    return new HttpResponseCache(android.net.http.HttpResponseCache.install(directory, maxSize));
  }