use of com.squareup.okhttp.internal.http.RawHeaders in project phonegap-facebook-plugin by Wizcorp.
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());
}
}
}
use of com.squareup.okhttp.internal.http.RawHeaders in project phonegap-facebook-plugin by Wizcorp.
the class HttpResponseCache method put.
@Override
public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
if (!(urlConnection instanceof HttpURLConnection)) {
return null;
}
HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
String requestMethod = httpConnection.getRequestMethod();
String key = uriToKey(uri);
if (requestMethod.equals("POST") || requestMethod.equals("PUT") || requestMethod.equals("DELETE")) {
try {
cache.remove(key);
} catch (IOException ignored) {
// The cache cannot be written.
}
return null;
} else if (!requestMethod.equals("GET")) {
// so is high and the benefit is low.
return null;
}
HttpEngine httpEngine = getHttpEngine(httpConnection);
if (httpEngine == null) {
// Don't cache unless the HTTP implementation is ours.
return null;
}
ResponseHeaders response = httpEngine.getResponseHeaders();
if (response.hasVaryAll()) {
return null;
}
RawHeaders varyHeaders = httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
Entry entry = new Entry(uri, varyHeaders, httpConnection);
DiskLruCache.Editor editor = null;
try {
editor = cache.edit(key);
if (editor == null) {
return null;
}
entry.writeTo(editor);
return new CacheRequestImpl(editor);
} catch (IOException e) {
abortQuietly(editor);
return null;
}
}
use of com.squareup.okhttp.internal.http.RawHeaders in project phonegap-facebook-plugin by Wizcorp.
the class HttpResponseCache method update.
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 {
// returns null if snapshot is not current
editor = snapshot.edit();
if (editor != null) {
entry.writeTo(editor);
editor.commit();
}
} catch (IOException e) {
abortQuietly(editor);
}
}
use of com.squareup.okhttp.internal.http.RawHeaders in project robovm by robovm.
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(route.address.authenticator, 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());
}
}
}
use of com.squareup.okhttp.internal.http.RawHeaders in project robovm by robovm.
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;
}
Aggregations