2003/02/22 03:55:06
[org.ibex.core.git] / src / org / xwt / HTTP.java
index 22a0761..acdfcc3 100644 (file)
@@ -39,6 +39,9 @@ public class HTTP {
     /** the socket's inputstream */
     InputStream in = null;
 
+    /** the socket's outputstream */
+    PrintWriter out = null;
+
     /** the username and password portions of the URL */
     String userInfo = null;
 
@@ -318,12 +321,24 @@ public class HTTP {
     // Everything Else ////////////////////////////////////////////////////////////////////////////
 
     private synchronized void connect() throws IOException {
-        if (sock != null) {
+        if (sock != null && !"".equals(originalUrl)) {
             if (in == null) in = new BufferedInputStream(sock.getInputStream());
             return;
         }
         // grab the userinfo; gcj doesn't have java.net.URL.getUserInfo()
         String url = originalUrl;
+
+        if ("".equals(url)) {
+            userInfo = "";
+            this.url = null;
+            port = 80;
+            path = "/RPC2";
+            host = "";
+            in = System.in;
+            out = new PrintWriter(System.out);
+            return;
+        }
+
         userInfo = url.substring(url.indexOf("://") + 3);
         userInfo = userInfo.indexOf('/') == -1 ? userInfo : userInfo.substring(0, userInfo.indexOf('/'));
         if (userInfo.indexOf('@') != -1) {
@@ -332,7 +347,7 @@ public class HTTP {
         } else {
             userInfo = null;
         }
-
+        
         if (url.startsWith("https:")) {
             this.url = new URL("http" + url.substring(5));
             ssl = true;
@@ -341,6 +356,7 @@ public class HTTP {
         } else {
             this.url = new URL(url);
         }
+
         if (!skipResolveCheck) resolveAndCheckIfFirewalled(this.url.getHost());
         port = this.url.getPort();
         path = this.url.getFile();
@@ -356,11 +372,12 @@ public class HTTP {
         if (sock == null) sock = attemptDirect();
         if (sock == null) throw new HTTPException("unable to contact host " + host);
         if (in == null) in = new BufferedInputStream(sock.getInputStream());
+        if (out == null) out = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()));
     }
 
     public void sendRequest(String contentType, String content) throws IOException {
 
-        PrintWriter pw = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()));
+        PrintWriter pw = out;
         if (content != null) {
             pw.print("POST " + path + " HTTP/1.1\r\n");
         int contentLength = content.substring(0, 2).equals("\r\n") ?