Search in sources :

Example 11 with RawHeaders

use of com.squareup.okhttp.internal.http.RawHeaders in project cordova-android-chromeview by thedracle.

the class Connection method makeTunnel.

/**
   * To make an HTTPS connection over an HTTP proxy, send an unencrypted
   * CONNECT request to create the proxy connection. This may need to be
   * retried if the proxy requires authorization.
   */
private void makeTunnel(TunnelRequest tunnelRequest) throws IOException {
    RawHeaders requestHeaders = tunnelRequest.getRequestHeaders();
    while (true) {
        out.write(requestHeaders.toBytes());
        RawHeaders responseHeaders = RawHeaders.fromBytes(in);
        switch(responseHeaders.getResponseCode()) {
            case HTTP_OK:
                return;
            case HTTP_PROXY_AUTH:
                requestHeaders = new RawHeaders(requestHeaders);
                URL url = new URL("https", tunnelRequest.host, tunnelRequest.port, "/");
                boolean credentialsFound = HttpAuthenticator.processAuthHeader(HTTP_PROXY_AUTH, responseHeaders, requestHeaders, route.proxy, url);
                if (credentialsFound) {
                    continue;
                } else {
                    throw new IOException("Failed to authenticate with proxy");
                }
            default:
                throw new IOException("Unexpected response code for CONNECT: " + responseHeaders.getResponseCode());
        }
    }
}
Also used : IOException(java.io.IOException) RawHeaders(com.squareup.okhttp.internal.http.RawHeaders) URL(java.net.URL)

Example 12 with RawHeaders

use of com.squareup.okhttp.internal.http.RawHeaders in project cordova-android-chromeview by thedracle.

the class TunnelRequest method getRequestHeaders.

/**
   * If we're creating a TLS tunnel, send only the minimum set of headers.
   * This avoids sending potentially sensitive data like HTTP cookies to
   * the proxy unencrypted.
   */
RawHeaders getRequestHeaders() {
    RawHeaders result = new RawHeaders();
    result.setRequestLine("CONNECT " + host + ":" + port + " HTTP/1.1");
    // Always set Host and User-Agent.
    result.set("Host", port == getDefaultPort("https") ? host : (host + ":" + port));
    result.set("User-Agent", userAgent);
    // Copy over the Proxy-Authorization header if it exists.
    if (proxyAuthorization != null) {
        result.set("Proxy-Authorization", proxyAuthorization);
    }
    // Always set the Proxy-Connection to Keep-Alive for the benefit of
    // HTTP/1.0 proxies like Squid.
    result.set("Proxy-Connection", "Keep-Alive");
    return result;
}
Also used : RawHeaders(com.squareup.okhttp.internal.http.RawHeaders)

Aggregations

RawHeaders (com.squareup.okhttp.internal.http.RawHeaders)12 IOException (java.io.IOException)9 DiskLruCache (com.squareup.okhttp.internal.DiskLruCache)6 HttpEngine (com.squareup.okhttp.internal.http.HttpEngine)6 ResponseHeaders (com.squareup.okhttp.internal.http.ResponseHeaders)6 HttpURLConnection (java.net.HttpURLConnection)3 URI (java.net.URI)3 URL (java.net.URL)3