aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Szymański <zbigniew.szymanski@wearezeta.com>2014-12-15 14:47:19 +0100
committerZbigniew Szymański <zbigniew.szymanski@wearezeta.com>2014-12-15 14:47:22 +0100
commitcd3f26489d57a2d413971c0c2906842f90a5e1d2 (patch)
tree2432b3286627318337d9888bfc00968fc9cff990
parent683da377b7ecfc187b0d8f1ead969a5a8a80a7d3 (diff)
downloadAndroidAsync-cd3f26489d57a2d413971c0c2906842f90a5e1d2.tar.gz
AndroidAsync-cd3f26489d57a2d413971c0c2906842f90a5e1d2.tar.bz2
AndroidAsync-cd3f26489d57a2d413971c0c2906842f90a5e1d2.zip
Fix SSL proxy tunneling.
Added Host header to CONNECT request, required by some proxies (for example 724 Solutions on swiss network). Changed status line handling to allow any 2xx response code. Removed check for empty second line, proxy is allowed to send any number of headers after status line in response.
-rw-r--r--AndroidAsync/src/com/koushikdutta/async/http/AsyncSSLSocketMiddleware.java18
1 files changed, 7 insertions, 11 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/http/AsyncSSLSocketMiddleware.java b/AndroidAsync/src/com/koushikdutta/async/http/AsyncSSLSocketMiddleware.java
index d557a31..dfee970 100644
--- a/AndroidAsync/src/com/koushikdutta/async/http/AsyncSSLSocketMiddleware.java
+++ b/AndroidAsync/src/com/koushikdutta/async/http/AsyncSSLSocketMiddleware.java
@@ -101,7 +101,8 @@ public class AsyncSSLSocketMiddleware extends AsyncSocketMiddleware {
// this SSL connection is proxied, must issue a CONNECT request to the proxy server
// http://stackoverflow.com/a/6594880/704837
- String connect = String.format("CONNECT %s:%s HTTP/1.1\r\n\r\n", uri.getHost(), port);
+ // some proxies also require 'Host' header, it should be safe to provide it every time
+ String connect = String.format("CONNECT %s:%s HTTP/1.1\r\nHost: %s\r\n\r\n", uri.getHost(), port, uri.getHost());
Util.writeAll(socket, connect.getBytes(), new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
@@ -116,22 +117,17 @@ public class AsyncSSLSocketMiddleware extends AsyncSocketMiddleware {
@Override
public void onStringAvailable(String s) {
if (statusLine == null) {
- statusLine = s;
- if (statusLine.length() > 128 || !statusLine.contains("200")) {
+ statusLine = s.trim();
+ if (!statusLine.matches("HTTP/1.\\d 2\\d\\d .*")) { // connect response is allowed to have any 2xx status code
socket.setDataCallback(null);
socket.setEndCallback(null);
- callback.onConnectCompleted(new IOException("non 200 status line"), socket);
+ callback.onConnectCompleted(new IOException("non 2xx status line"), socket);
}
}
- else {
+ else if (TextUtils.isEmpty(s.trim())) { // skip all headers, complete handshake once empty line is received
socket.setDataCallback(null);
socket.setEndCallback(null);
- if (TextUtils.isEmpty(s.trim())) {
- tryHandshake(socket, data, uri, port, callback);
- }
- else {
- callback.onConnectCompleted(new IOException("unknown second status line"), socket);
- }
+ tryHandshake(socket, data, uri, port, callback);
}
}
});