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


Hi list,


I commited the attached patch to add HTTP 1.1 and HTTP POST support at once.
This fixes libgcj PR/6302 and libgcj PR/7752.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2499
diff -u -b -B -r1.2499 ChangeLog
--- ChangeLog	30 Dec 2003 13:21:15 -0000	1.2499
+++ ChangeLog	30 Dec 2003 13:39:41 -0000
@@ -1,3 +1,17 @@
+2003-12-30  Michael Koch  <konqueror@gmx.de>
+
+	* gnu/java/net/protocol/http/Connection.java
+	(outputStream): New field.
+	(bufferedOutputStream): New field.
+	(connect): Initialize outputStream and bufferedOutputStream.
+	(sendRequest): Create PrintWriter object from outputStream,
+	support HTTP 1.1, send missing HTTP headers and buffered output data
+	for POST method.
+	(getOutputStream): Set request method to POST if output stream is
+	used, return bufferedOutputStream.
+	(setRequestMethod): Allow HEAD and POST methods.
+	This fixes libgcj PR/6302 and libgcj PR/7752.
+
 2003-12-30  Guilhem Lavaux <guilhem@kaffe.org>
 
 	* java/io/LineNumberReader.java
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.11
diff -u -b -B -r1.11 Connection.java
--- gnu/java/net/protocol/http/Connection.java	30 Dec 2003 12:02:47 -0000	1.11
+++ gnu/java/net/protocol/http/Connection.java	30 Dec 2003 13:39:41 -0000
@@ -39,6 +39,8 @@
 package gnu.java.net.protocol.http;
 
 import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.InputStream;
 import java.io.IOException;
@@ -106,6 +108,17 @@
   private DataInputStream inputStream;
 
   /**
+   * The OutputStream for this connection
+   */
+  private OutputStream outputStream;
+
+  /**
+   * bufferedOutputStream is a buffer to contain content of the HTTP request,
+   * and will be written to outputStream all at once
+   */
+  private ByteArrayOutputStream bufferedOutputStream;
+
+  /**
    * This object holds the request properties.
    */
   private HashMap requestProperties = new HashMap();
@@ -153,6 +166,8 @@
 
     inputStream =
       new DataInputStream(new BufferedInputStream(socket.getInputStream()));
+    outputStream = new BufferedOutputStream (socket.getOutputStream());
+    bufferedOutputStream = new ByteArrayOutputStream (256); //default is too small
 
     sendRequest();
     receiveReply();
@@ -185,16 +200,32 @@
   void sendRequest() throws IOException
   {
     // Create PrintWriter for easier sending of headers.
-    PrintWriter outputWriter = new PrintWriter(socket.getOutputStream());
+    PrintWriter outputWriter = new PrintWriter(outputStream);
     
     // Send request including any request properties that were set.
     outputWriter.print (getRequestMethod() + " " + url.getFile()
-                        + " HTTP/1.0\r\n");
+                        + " HTTP/1.1\r\n");
 
     // Set additional HTTP headers.
     if (getRequestProperty ("Host") == null)
       setRequestProperty ("Host", url.getHost());
     
+    if (getRequestProperty ("Connection") == null)
+      setRequestProperty ("Connection", "Close");
+    
+    if (getRequestProperty ("user-agent") == null)
+      setRequestProperty ("user-agent", "gnu-libgcj/"
+                          + System.getProperty ("classpath.version"));
+    
+    if (getRequestProperty ("accept") == null)
+      setRequestProperty ("accept", "*/*");
+    
+    if (getRequestProperty ("Content-type") == null)
+      setRequestProperty ("Content-type", "application/x-www-form-urlencoded");
+
+    // Set correct content length.
+    setRequestProperty ("Content-length", String.valueOf (bufferedOutputStream.size()));
+
     // Write all req_props name-value pairs to the output writer.
     Iterator itr = getRequestProperties().entrySet().iterator();
 
@@ -207,6 +238,10 @@
     // One more CR-LF indicates end of header.
     outputWriter.print ("\r\n");
     outputWriter.flush();
+
+    // Write content
+    bufferedOutputStream.writeTo (outputStream);
+    outputStream.flush();
   }
 
   /**
@@ -352,7 +387,7 @@
     if (!connected)
       connect();
     
-    return socket.getOutputStream();
+    return bufferedOutputStream;
   }
 
   /**
@@ -367,7 +402,9 @@
   {
     method = method.toUpperCase();
     
-    if (method.equals("GET"))
+    if (method.equals("GET")
+        || method.equals("HEAD")
+        || method.equals("POST"))
       super.setRequestMethod (method);
     else
       throw new ProtocolException ("Unsupported or unknown request method " +

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