You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HTTPConnectSocket.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // HTTPConnectSocket.java together with HTTPConnectSocketFactory.java
  21. // implement an alternate way to connect to VNC servers via one or two
  22. // HTTP proxies supporting the HTTP CONNECT method.
  23. //
  24. import java.net.*;
  25. import java.io.*;
  26. class HTTPConnectSocket extends Socket {
  27. public HTTPConnectSocket(String host, int port,
  28. String proxyHost, int proxyPort)
  29. throws IOException {
  30. // Connect to the specified HTTP proxy
  31. super(proxyHost, proxyPort);
  32. // Send the CONNECT request
  33. getOutputStream().write(("CONNECT " + host + ":" + port +
  34. " HTTP/1.0\r\n\r\n").getBytes());
  35. // Read the first line of the response
  36. DataInputStream is = new DataInputStream(getInputStream());
  37. String str = is.readLine();
  38. // Check the HTTP error code -- it should be "200" on success
  39. if (!str.startsWith("HTTP/1.0 200 ")) {
  40. if (str.startsWith("HTTP/1.0 "))
  41. str = str.substring(9);
  42. throw new IOException("Proxy reports \"" + str + "\"");
  43. }
  44. // Success -- skip remaining HTTP headers
  45. do {
  46. str = is.readLine();
  47. } while (str.length() != 0);
  48. }
  49. }