1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
190 }
191 }
192 return -1;
193 }
194
195 public void init() {
196 try {
197 byte[] buf = readHeaders(clientIn);
198 int p = findCRLF(buf);
199 if (p == -1) {
200 close();
201 return;
202 }
203 String cmd = new String(buf, 0, p, "US-ASCII");
204 String[] params = cmd.split(" ");
205 if (params[0].equals("CONNECT")) {
206 doTunnel(params[1]);
207 } else {
208 doProxy(params[1], buf, p, cmd);
209 }
210 } catch (IOException e) {
211 if (debug) {
212 System.out.println (e);
213 }
214 try {close(); } catch (IOException e1) {}
215 }
216 }
217
218 void doProxy(String dest, byte[] buf, int p, String cmdLine)
219 throws IOException
220 {
221 try {
222 URI uri = new URI(dest);
223 if (!uri.isAbsolute()) {
224 throw new IOException("request URI not absolute");
225 }
226 dest = uri.getAuthority();
227 // now extract the path from the URI and recreate the cmd line
228 int sp = cmdLine.indexOf(' ');
229 String method = cmdLine.substring(0, sp);
230 cmdLine = method + " " + uri.getPath() + " HTTP/1.1";
|
1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
190 }
191 }
192 return -1;
193 }
194
195 public void init() {
196 try {
197 byte[] buf = readHeaders(clientIn);
198 int p = findCRLF(buf);
199 if (p == -1) {
200 close();
201 return;
202 }
203 String cmd = new String(buf, 0, p, "US-ASCII");
204 String[] params = cmd.split(" ");
205 if (params[0].equals("CONNECT")) {
206 doTunnel(params[1]);
207 } else {
208 doProxy(params[1], buf, p, cmd);
209 }
210 } catch (Throwable e) {
211 if (debug) {
212 System.out.println (e);
213 }
214 try {close(); } catch (IOException e1) {}
215 }
216 }
217
218 void doProxy(String dest, byte[] buf, int p, String cmdLine)
219 throws IOException
220 {
221 try {
222 URI uri = new URI(dest);
223 if (!uri.isAbsolute()) {
224 throw new IOException("request URI not absolute");
225 }
226 dest = uri.getAuthority();
227 // now extract the path from the URI and recreate the cmd line
228 int sp = cmdLine.indexOf(' ');
229 String method = cmdLine.substring(0, sp);
230 cmdLine = method + " " + uri.getPath() + " HTTP/1.1";
|