com.squareup.okhttp.internal.http.HttpEngine Java Examples

The following examples show how to use com.squareup.okhttp.internal.http.HttpEngine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpResponseCache.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #2
Source File: HttpResponseCache.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #3
Source File: HttpResponseCache.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection) throws IOException {
    HttpEngine httpEngine = getHttpEngine(httpConnection);
    URI uri = httpEngine.getUri();
    ResponseHeaders response = httpEngine.getResponseHeaders();
    RawHeaders varyHeaders = httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
    Entry entry = new Entry(uri, varyHeaders, httpConnection);
    DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse) ? ((EntryCacheResponse) conditionalCacheHit).snapshot : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
    DiskLruCache.Editor editor = null;
    try {
        editor = snapshot.edit(); // returns null if snapshot is not current
        if (editor != null) {
            entry.writeTo(editor);
            editor.commit();
        }
    } catch (IOException e) {
        abortQuietly(editor);
    }
}
 
Example #4
Source File: HttpResponseCache.java    From wildfly-samples with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #5
Source File: HttpURLConnectionImpl.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Override public final InputStream getInputStream() throws IOException {
    if (!doInput) {
      throw new ProtocolException("This protocol does not support input");
    }

    HttpEngine response = getResponse();

    // if the requested file does not exist, throw an exception formerly the
    // Error page from the server was returned if the requested file was
    // text/html this has changed to return FileNotFoundException for all
    // file types
//    if (getResponseCode() >= HTTP_BAD_REQUEST) {
//      throw new FileNotFoundException(url.toString());
//    }

    return response.getResponse().body().byteStream();
  }
 
Example #6
Source File: HttpResponseCache.java    From reader with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #7
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #8
Source File: HttpResponseCache.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #9
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #10
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #11
Source File: HttpResponseCache.java    From reader with MIT License 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #12
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
private void update(CacheResponse conditionalCacheHit, HttpURLConnection httpConnection)
    throws IOException {
  HttpEngine httpEngine = getHttpEngine(httpConnection);
  URI uri = httpEngine.getUri();
  ResponseHeaders response = httpEngine.getResponseHeaders();
  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Snapshot snapshot = (conditionalCacheHit instanceof EntryCacheResponse)
      ? ((EntryCacheResponse) conditionalCacheHit).snapshot
      : ((EntrySecureCacheResponse) conditionalCacheHit).snapshot;
  DiskLruCache.Editor editor = null;
  try {
    editor = snapshot.edit(); // returns null if snapshot is not current
    if (editor != null) {
      entry.writeTo(editor);
      editor.commit();
    }
  } catch (IOException e) {
    abortQuietly(editor);
  }
}
 
Example #13
Source File: Job.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
HttpEngine newEngine(Connection connection) throws IOException {
  String protocol = request.url().getProtocol();
  RawHeaders requestHeaders = request.rawHeaders();
  if (protocol.equals("http")) {
    return new HttpEngine(client, this, request.method(), requestHeaders, connection, null);
  } else if (protocol.equals("https")) {
    return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null);
  } else {
    throw new AssertionError();
  }
}
 
Example #14
Source File: Job.java    From reader with MIT License 5 votes vote down vote up
HttpEngine newEngine(Connection connection) throws IOException {
  String protocol = request.url().getProtocol();
  RawHeaders requestHeaders = request.rawHeaders();
  if (protocol.equals("http")) {
    return new HttpEngine(client, this, request.method(), requestHeaders, connection, null);
  } else if (protocol.equals("https")) {
    return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null);
  } else {
    throw new AssertionError();
  }
}
 
Example #15
Source File: HttpResponseCache.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #16
Source File: HttpResponseCache.java    From reader with MIT License 5 votes vote down vote up
/**
 * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa), the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpConnection) {
  HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
 
Example #17
Source File: HttpResponseCache.java    From reader with MIT License 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #18
Source File: Job.java    From reader with MIT License 5 votes vote down vote up
HttpEngine newEngine(Connection connection) throws IOException {
  String protocol = request.url().getProtocol();
  RawHeaders requestHeaders = request.rawHeaders();
  if (protocol.equals("http")) {
    return new HttpEngine(client, this, request.method(), requestHeaders, connection, null);
  } else if (protocol.equals("https")) {
    return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null);
  } else {
    throw new AssertionError();
  }
}
 
Example #19
Source File: HttpResponseCache.java    From reader with MIT License 5 votes vote down vote up
/**
 * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa), the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpConnection) {
  HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
 
Example #20
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa), the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpConnection) {
  HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
 
Example #21
Source File: HttpResponseCache.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #22
Source File: HttpResponseCache.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #23
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #24
Source File: HttpResponseCache.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa), the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpConnection) {
  HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
 
Example #25
Source File: OkHttpClient_2_x_IT.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private Method getConnectMethod() {
    try {
        // [2.3.0,)
        return HttpEngine.class.getDeclaredMethod("connect");
    } catch (NoSuchMethodException e) {
        try {
            // [2.0.0,2.2.max]
            return HttpEngine.class.getDeclaredMethod("connect", Request.class);
        } catch (NoSuchMethodException e1) {
            throw new AssertionError("Expected methods connect() / connect(com.squareup.okhttp.Request) not found in HttpEngine class");
        }
    }
}
 
Example #26
Source File: HttpResponseCache.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #27
Source File: Job.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
HttpEngine newEngine(Connection connection) throws IOException {
  String protocol = request.url().getProtocol();
  RawHeaders requestHeaders = request.rawHeaders();
  if (protocol.equals("http")) {
    return new HttpEngine(client, this, request.method(), requestHeaders, connection, null);
  } else if (protocol.equals("https")) {
    return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null);
  } else {
    throw new AssertionError();
  }
}
 
Example #28
Source File: Job.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
HttpEngine newEngine(Connection connection) throws IOException {
  String protocol = request.url().getProtocol();
  RawHeaders requestHeaders = request.rawHeaders();
  if (protocol.equals("http")) {
    return new HttpEngine(client, this, request.method(), requestHeaders, connection, null);
  } else if (protocol.equals("https")) {
    return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null);
  } else {
    throw new AssertionError();
  }
}
 
Example #29
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
private HttpEngine getHttpEngine(URLConnection httpConnection) {
  if (httpConnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  } else if (httpConnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpConnection).getHttpEngine();
  } else {
    return null;
  }
}
 
Example #30
Source File: HttpResponseCache.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa), the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpConnection) {
  HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpConnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}