2 // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved.
4 // This is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This software is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this software; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // HTTPConnectSocket.java together with HTTPConnectSocketFactory.java
22 // implement an alternate way to connect to VNC servers via one or two
23 // HTTP proxies supporting the HTTP CONNECT method.
29 class HTTPConnectSocket extends Socket {
31 public HTTPConnectSocket(String host, int port,
32 String proxyHost, int proxyPort)
35 // Connect to the specified HTTP proxy
36 super(proxyHost, proxyPort);
38 // Send the CONNECT request
39 getOutputStream().write(("CONNECT " + host + ":" + port +
40 " HTTP/1.0\r\n\r\n").getBytes());
42 // Read the first line of the response
43 DataInputStream is = new DataInputStream(getInputStream());
44 String str = is.readLine();
46 // Check the HTTP error code -- it should be "200" on success
47 if (!str.startsWith("HTTP/1.0 200 ")) {
48 if (str.startsWith("HTTP/1.0 "))
49 str = str.substring(9);
50 throw new IOException("Proxy reports \"" + str + "\"");
53 // Success -- skip remaining HTTP headers
56 } while (str.length() != 0);