This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: gnu.java.net.protocol.http.Connection


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I commited another patch to gnu.java.net.protocol.http.Connection to 
make it more in line with classpath.



Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/zK1cWSOgCCdjSDsRAjxZAJ9lQLN6woIbo4EDZnvcSVh+BwEILQCeI8wx
auN88FCQonbjCbcGM3T8mJU=
=FXHS
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2396
diff -u -b -B -r1.2396 ChangeLog
--- ChangeLog	2 Dec 2003 13:44:22 -0000	1.2396
+++ ChangeLog	2 Dec 2003 14:08:13 -0000
@@ -1,5 +1,14 @@
 2003-12-02  Michael Koch  <konqueror@gmx.de>
 
+	* gnu/java/net/protocol/http/Connection.java
+	(Connection): Initialize doOutput to false;
+	(connect): Initialize inputStream, moved "send request" code to new
+	method.
+	(sendRequest): New method.
+	(getHttpHeaders): Don't reinitialize inputStream.
+
+2003-12-02  Michael Koch  <konqueror@gmx.de>
+
 	* gnu/java/net/protocol//http/Connection.java
 	(defRequestProperties): Removed. This dont gets used since JDK 1.3.
 	(requestProperties): Initialize, documentation added.
Index: gnu/java/net/protocol/http/Connection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/protocol/http/Connection.java,v
retrieving revision 1.5
diff -u -b -B -r1.5 Connection.java
--- gnu/java/net/protocol/http/Connection.java	2 Dec 2003 13:44:23 -0000	1.5
+++ gnu/java/net/protocol/http/Connection.java	2 Dec 2003 14:08:13 -0000
@@ -117,6 +117,9 @@
   protected Connection(URL url)
   {
     super(url);
+
+    /* Set up some variables */
+    doOutput = false;
   }
 
   public void setRequestProperty(String key, String value)
@@ -160,17 +163,15 @@
 	socket = new Socket(url.getHost(), port);
       }
 
-    PrintWriter out = new PrintWriter(socket.getOutputStream());
+    // Originally tried using a BufferedReader here to take advantage of
+    // the readLine method and avoid the following, but the buffer read
+    // past the end of the headers so the first part of the content was lost.
+    // It is probably more robust than it needs to be, e.g. the byte[]
+    // is unlikely to overflow and a '\r' should always be followed by a '\n',
+    // but it is better to be safe just in case.
+    inputStream = new BufferedInputStream(socket.getInputStream());
 
-    // Send request including any request properties that were set.
-    out.print(getRequestMethod() + " " + url.getFile() + " HTTP/1.0\r\n");
-    out.print("Host: " + url.getHost() + ":" + port + "\r\n");
-    Enumeration reqKeys = requestProperties.keys();
-    Enumeration reqVals = requestProperties.elements();
-    while (reqKeys.hasMoreElements())
-      out.print(reqKeys.nextElement() + ": " + reqVals.nextElement() + "\r\n");
-    out.print("\r\n");
-    out.flush();    
+    sendRequest();
     getHttpHeaders();
     connected = true;
   }
@@ -195,6 +196,34 @@
   }
 
   /**
+   * Write HTTP request header and content to outputWriter.
+   */
+  void sendRequest() throws IOException
+  {
+    // Create PrintWriter for easier sending of headers.
+    PrintWriter outputWriter = new PrintWriter(socket.getOutputStream());
+    
+    // Send request including any request properties that were set.
+    outputWriter.print (getRequestMethod() + " " + url.getFile()
+                        + " HTTP/1.0\r\n");
+
+    // Set additional HTTP headers.
+    if (getRequestProperty ("Host") == null)
+      setRequestProperty ("Host", url.getHost());
+    
+    // Write all req_props name-value pairs to the output writer.
+    Enumeration reqKeys = requestProperties.keys();
+    Enumeration reqVals = requestProperties.elements();
+    
+    while (reqKeys.hasMoreElements())
+      outputWriter.print (reqKeys.nextElement() + ": " + reqVals.nextElement() + "\r\n");
+    
+    // One more CR-LF indicates end of header.
+    outputWriter.print ("\r\n");
+    outputWriter.flush();
+  }
+
+  /**
    * Return a boolean indicating whether or not this connection is
    * going through a proxy
    *
@@ -318,14 +347,6 @@
    */
   private void getHttpHeaders() throws IOException
   {
-    // Originally tried using a BufferedReader here to take advantage of
-    // the readLine method and avoid the following, but the buffer read
-    // past the end of the headers so the first part of the content was lost.
-    // It is probably more robust than it needs to be, e.g. the byte[]
-    // is unlikely to overflow and a '\r' should always be followed by a '\n',
-    // but it is better to be safe just in case.
-    inputStream = new BufferedInputStream(socket.getInputStream());
-
     int buflen = 100;
     byte[] buf = new byte[buflen];
     String line = "";

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]