75 |
* The socket we are connected to |
* The socket we are connected to |
76 |
*/ |
*/ |
77 |
private Socket socket; |
private Socket socket; |
78 |
|
|
79 |
|
private static String proxyHost = null; |
80 |
|
private static int proxyPort = 80; |
81 |
|
private static boolean proxyInUse = false; |
82 |
|
|
83 |
|
static |
84 |
|
{ |
85 |
|
// Recognize some networking properties listed at |
86 |
|
// http://java.sun.com/j2se/1.4/docs/guide/net/properties.html. |
87 |
|
String port = null; |
88 |
|
proxyHost = System.getProperty ("http.proxyHost"); |
89 |
|
|
90 |
|
if (proxyHost != null) |
91 |
|
{ |
92 |
|
proxyInUse = true; |
93 |
|
|
94 |
|
if ((port = System.getProperty ("http.proxyPort")) != null) |
95 |
|
{ |
96 |
|
try |
97 |
|
{ |
98 |
|
proxyPort = Integer.parseInt (port); |
99 |
|
} |
100 |
|
catch (Throwable t) |
101 |
|
{ |
102 |
|
// Nothing. |
103 |
|
} |
104 |
|
} |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
/** |
/** |
109 |
* The InputStream for this connection. |
* The InputStream for this connection. |
148 |
*/ |
*/ |
149 |
public void connect() throws IOException |
public void connect() throws IOException |
150 |
{ |
{ |
151 |
// Connect up |
// Call is ignored if already connected. |
152 |
if (url.getPort() == -1) |
if (connected) |
153 |
socket = new Socket(url.getHost(), 80); |
return; |
154 |
else |
|
155 |
socket = new Socket(url.getHost(), url.getPort()); |
// Get address and port number. |
156 |
|
int port; |
157 |
|
|
158 |
|
if (proxyInUse) |
159 |
|
{ |
160 |
|
port = proxyPort; |
161 |
|
socket = new Socket (proxyHost, port); |
162 |
|
} |
163 |
|
else |
164 |
|
{ |
165 |
|
if ((port = url.getPort()) == -1) |
166 |
|
port = 80; |
167 |
|
|
168 |
|
// Open socket and output stream. |
169 |
|
socket = new Socket (url.getHost(), port); |
170 |
|
} |
171 |
|
|
172 |
if (doInput) |
if (doInput) |
173 |
inputStream |
inputStream |
174 |
= new DataInputStream (new BufferedInputStream (socket.getInputStream())); |
= new DataInputStream (new BufferedInputStream (socket.getInputStream())); |
214 |
+ " HTTP/1.1\r\n"); |
+ " HTTP/1.1\r\n"); |
215 |
|
|
216 |
// Set additional HTTP headers. |
// Set additional HTTP headers. |
217 |
if (getRequestProperty ("host") == null) |
if (getRequestProperty ("Host") == null) |
218 |
{ |
{ |
219 |
setRequestProperty ("Host", url.getHost()); |
setRequestProperty ("Host", url.getHost()); |
220 |
} |
} |
384 |
*/ |
*/ |
385 |
public boolean usingProxy() |
public boolean usingProxy() |
386 |
{ |
{ |
387 |
return false; |
return proxyInUse; |
388 |
} |
} |
389 |
|
|
390 |
/** |
/** |