Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved. |
| 3 | // |
| 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. |
| 8 | // |
| 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. |
| 13 | // |
| 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, |
| 17 | // USA. |
| 18 | // |
| 19 | |
| 20 | // |
| 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. |
| 24 | // |
| 25 | |
Adam Tkac | f53e62a | 2009-03-13 13:20:26 +0000 | [diff] [blame] | 26 | package com.tigervnc.vncviewer; |
Constantin Kaplinsky | 90d8a50 | 2008-04-14 09:45:50 +0000 | [diff] [blame] | 27 | |
Constantin Kaplinsky | 2844fd5 | 2008-04-14 08:02:25 +0000 | [diff] [blame] | 28 | import java.net.*; |
| 29 | import java.io.*; |
| 30 | |
| 31 | class HTTPConnectSocket extends Socket { |
| 32 | |
| 33 | public HTTPConnectSocket(String host, int port, |
| 34 | String proxyHost, int proxyPort) |
| 35 | throws IOException { |
| 36 | |
| 37 | // Connect to the specified HTTP proxy |
| 38 | super(proxyHost, proxyPort); |
| 39 | |
| 40 | // Send the CONNECT request |
| 41 | getOutputStream().write(("CONNECT " + host + ":" + port + |
| 42 | " HTTP/1.0\r\n\r\n").getBytes()); |
| 43 | |
| 44 | // Read the first line of the response |
| 45 | DataInputStream is = new DataInputStream(getInputStream()); |
| 46 | String str = is.readLine(); |
| 47 | |
| 48 | // Check the HTTP error code -- it should be "200" on success |
| 49 | if (!str.startsWith("HTTP/1.0 200 ")) { |
| 50 | if (str.startsWith("HTTP/1.0 ")) |
| 51 | str = str.substring(9); |
| 52 | throw new IOException("Proxy reports \"" + str + "\""); |
| 53 | } |
| 54 | |
| 55 | // Success -- skip remaining HTTP headers |
| 56 | do { |
| 57 | str = is.readLine(); |
| 58 | } while (str.length() != 0); |
| 59 | } |
| 60 | } |
| 61 | |