public Socket createSocket(String host, int port) throws IOException, FingerprintException, FingerprintError { Socket s = new Socket(); s.connect(new InetSocketAddress(proxyHost, proxyPort), 1000 * timeout); PrintWriter out = new PrintWriter(s.getOutputStream()); InputStreamReader isr = new InputStreamReader(s.getInputStream()); BufferedReader in = new BufferedReader(isr); String[] connHdr = { "CONNECT " + host + ":" + port + " HTTP/1.1", "Host: " + host + ":" + port, "Proxy-Connection: close" }; String[] connReq = null; if (authRequired) { connReq = new String[connHdr.length + 1]; for (int i = 0; i < connHdr.length; i++) { connReq[i] = connHdr[i]; } connReq[connHdr.length] = "Proxy-Authorization: " + authenticator; } else { connReq = new String[connHdr.length]; for (int i = 0; i < connHdr.length; i++) { connReq[i] = connHdr[i]; } } sendRequest(out, connReq); HttpResponseHeader hdr = new HttpResponseHeader(in); int status = hdr.getStatusCode(); if (Debug.get(Debug.Communication)) { System.err.println("Got status " + status); } /* Now check the status code and act upon it */ if ((status / 100) == 2) { // Code is 2xx return s; } if (((status / 100) == 4) && (status != 407)) { throw new HttpProxyError("Proxy request failed"); } if ((status == 407) && authRequired) { /* We already sent authorisation info, * but the proxy did not accept it. * So we can only stop here, as * we do not have the right credentials * at hand. */ throw new HttpProxyError("Cannot authenticate " + "to proxy, wrong " + "credentials?"); } if (status == 407) { if (Debug.get(Debug.SockInit)) { System.err.println("Preparing proxy " + "authenticator for " + hdr.getProxyAuthInfo()); } prepareAuthorisation(hdr.getProxyAuthInfo()); authRequired = true; return createSocket(host, port); } return s; }