comparison src/ch/ethz/ssh2/transport/HTTPProxyClientTransportManager.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 91a31873c42a
children
comparison
equal deleted inserted replaced
305:d2b303406d63 307:071eccdff8ea
32 this.pd = pd; 32 this.pd = pd;
33 } 33 }
34 34
35 @Override 35 @Override
36 protected void connect(final String hostname, final int port, final int connectTimeout) throws IOException { 36 protected void connect(final String hostname, final int port, final int connectTimeout) throws IOException {
37
38 sock.connect(new InetSocketAddress(pd.proxyHost, pd.proxyPort), connectTimeout); 37 sock.connect(new InetSocketAddress(pd.proxyHost, pd.proxyPort), connectTimeout);
39
40 // Tell the proxy where we actually want to connect to 38 // Tell the proxy where we actually want to connect to
41 StringBuilder sb = new StringBuilder(); 39 StringBuilder sb = new StringBuilder();
42
43 sb.append("CONNECT "); 40 sb.append("CONNECT ");
44 sb.append(hostname); 41 sb.append(hostname);
45 sb.append(':'); 42 sb.append(':');
46 sb.append(port); 43 sb.append(port);
47 sb.append(" HTTP/1.0\r\n"); 44 sb.append(" HTTP/1.0\r\n");
48 45
49 if((pd.proxyUser != null) && (pd.proxyPass != null)) { 46 if ((pd.proxyUser != null) && (pd.proxyPass != null)) {
50 String credentials = pd.proxyUser + ":" + pd.proxyPass; 47 String credentials = pd.proxyUser + ":" + pd.proxyPass;
51 char[] encoded = Base64.encode(StringEncoder.GetBytes(credentials)); 48 char[] encoded = Base64.encode(StringEncoder.GetBytes(credentials));
52 sb.append("Proxy-Authorization: Basic "); 49 sb.append("Proxy-Authorization: Basic ");
53 sb.append(encoded); 50 sb.append(encoded);
54 sb.append("\r\n"); 51 sb.append("\r\n");
55 } 52 }
56 53
57 if(pd.requestHeaderLines != null) { 54 if (pd.requestHeaderLines != null) {
58 for(int i = 0; i < pd.requestHeaderLines.length; i++) { 55 for (int i = 0; i < pd.requestHeaderLines.length; i++) {
59 if(pd.requestHeaderLines[i] != null) { 56 if (pd.requestHeaderLines[i] != null) {
60 sb.append(pd.requestHeaderLines[i]); 57 sb.append(pd.requestHeaderLines[i]);
61 sb.append("\r\n"); 58 sb.append("\r\n");
62 } 59 }
63 } 60 }
64 } 61 }
65 62
66 sb.append("\r\n"); 63 sb.append("\r\n");
67
68 OutputStream out = sock.getOutputStream(); 64 OutputStream out = sock.getOutputStream();
69
70 out.write(StringEncoder.GetBytes(sb.toString())); 65 out.write(StringEncoder.GetBytes(sb.toString()));
71 out.flush(); 66 out.flush();
72
73 // Parse the HTTP response 67 // Parse the HTTP response
74
75 InputStream in = sock.getInputStream(); 68 InputStream in = sock.getInputStream();
76
77 final LineNumberReader reader = new LineNumberReader(new InputStreamReader(in)); 69 final LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
78 String httpReponse = reader.readLine(); 70 String httpReponse = reader.readLine();
79 71
80 if(!httpReponse.startsWith("HTTP/")) { 72 if (!httpReponse.startsWith("HTTP/")) {
81 throw new IOException("The proxy did not send back a valid HTTP response."); 73 throw new IOException("The proxy did not send back a valid HTTP response.");
82 } 74 }
83 75
84 // "HTTP/1.X XYZ X" => 14 characters minimum 76 // "HTTP/1.X XYZ X" => 14 characters minimum
85 77
86 if((httpReponse.length() < 14) || (httpReponse.charAt(8) != ' ') || (httpReponse.charAt(12) != ' ')) { 78 if ((httpReponse.length() < 14) || (httpReponse.charAt(8) != ' ') || (httpReponse.charAt(12) != ' ')) {
87 throw new IOException("The proxy did not send back a valid HTTP response."); 79 throw new IOException("The proxy did not send back a valid HTTP response.");
88 } 80 }
89 81
90 int errorCode; 82 int errorCode;
91 83
92 try { 84 try {
93 errorCode = Integer.parseInt(httpReponse.substring(9, 12)); 85 errorCode = Integer.parseInt(httpReponse.substring(9, 12));
94 } 86 }
95 catch(NumberFormatException ignore) { 87 catch (NumberFormatException ignore) {
96 throw new IOException("The proxy did not send back a valid HTTP response."); 88 throw new IOException("The proxy did not send back a valid HTTP response.");
97 } 89 }
98 90
99 if((errorCode < 0) || (errorCode > 999)) { 91 if ((errorCode < 0) || (errorCode > 999)) {
100 throw new IOException("The proxy did not send back a valid HTTP response."); 92 throw new IOException("The proxy did not send back a valid HTTP response.");
101 } 93 }
102 94
103 if(errorCode != 200) { 95 if (errorCode != 200) {
104 throw new HTTPProxyException(httpReponse.substring(13), errorCode); 96 throw new HTTPProxyException(httpReponse.substring(13), errorCode);
105 } 97 }
106 98
107 while(reader.readLine() != null) { 99 while (reader.readLine() != null) {
108 // Read until empty line 100 // Read until empty line
109 } 101 }
110 } 102 }
111 } 103 }