aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-12-30 13:43:24 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-12-30 13:43:24 +0000
commitf04f5b1fadf9c8ef67fdbdc98763ba69f3033274 (patch)
tree0d6e5313e0d2acafa10754ca9295b42474af4efd
parent50e8c419f93ca99039d60ba32068ae637d700c71 (diff)
downloadgcc-f04f5b1fadf9c8ef67fdbdc98763ba69f3033274.zip
gcc-f04f5b1fadf9c8ef67fdbdc98763ba69f3033274.tar.gz
gcc-f04f5b1fadf9c8ef67fdbdc98763ba69f3033274.tar.bz2
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. From-SVN: r75233
-rw-r--r--libjava/ChangeLog14
-rw-r--r--libjava/gnu/java/net/protocol/http/Connection.java45
2 files changed, 55 insertions, 4 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index f7fbbb7..639b936 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -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
diff --git a/libjava/gnu/java/net/protocol/http/Connection.java b/libjava/gnu/java/net/protocol/http/Connection.java
index 1a6d45c..0bc50d1 100644
--- a/libjava/gnu/java/net/protocol/http/Connection.java
+++ b/libjava/gnu/java/net/protocol/http/Connection.java
@@ -39,6 +39,8 @@ exception statement from your version. */
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 @@ public final class Connection extends HttpURLConnection
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 @@ public final class Connection extends HttpURLConnection
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 @@ public final class Connection extends HttpURLConnection
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 @@ public final class Connection extends HttpURLConnection
// 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 @@ public final class Connection extends HttpURLConnection
if (!connected)
connect();
- return socket.getOutputStream();
+ return bufferedOutputStream;
}
/**
@@ -367,7 +402,9 @@ public final class Connection extends HttpURLConnection
{
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 " +