This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
Re: java.net/170: HTTP client code treats headers as body
- To: warrenl at cygnus dot com
- Subject: Re: java.net/170: HTTP client code treats headers as body
- From: John Stracke <francis at ecal dot com>
- Date: 10 Mar 2000 03:16:00 -0000
- Cc: java-prs at sourceware dot cygnus dot com,
- Reply-To: John Stracke <francis at ecal dot com>
The following reply was made to PR java.net/170; it has been noted by GNATS.
From: John Stracke <francis@ecal.com>
To: Bryce McKinlay <bryce@albatross.co.nz>, java-gnats@sourceware.cygnus.com
Cc:
Subject: Re: java.net/170: HTTP client code treats headers as body
Date: Thu, 09 Mar 2000 22:05:30 -0500
John Stracke wrote:
> gcj doesn't currently implement getResponseCode() or getResponseMessage(). I'll
> write them tonight or tomorrow.
Here's the updated patch:
--- libgcj-2.95.1-orig/libjava/gnu/gcj/protocol/http/Connection.java Thu Apr 15
17:33:38 1999
+++ libgcj-2.95.1/libjava/gnu/gcj/protocol/http/Connection.java Thu Mar 9 21:58:05
2000
@@ -46,6 +46,18 @@
requestProperties = (Hashtable) defRequestProperties.clone();
}
+ public int getResponseCode() throws IOException
+ {
+ getHttpHeaders();
+ return responseCode;
+ }
+
+ public String getResponseMessage() throws IOException
+ {
+ getHttpHeaders();
+ return responseMessage;
+ }
+
// Override method in URLConnection.
public static void setDefaultRequestProperty(String key, String value)
{
@@ -94,7 +106,7 @@
PrintWriter out = new PrintWriter(sock.getOutputStream());
// Send request including any request properties that were set.
- out.print(getRequestMethod() + " " + url.getFile() + " HTTP/1.1\n");
+ out.print(getRequestMethod() + " " + url.getFile() + " HTTP/1.0\n");
out.print("Host: " + url.getHost() + ":" + port + "\n");
Enumeration reqKeys = requestProperties.keys();
Enumeration reqVals = requestProperties.elements();
@@ -137,8 +149,7 @@
if (! doInput)
throw new ProtocolException("Can't open InputStream if doInput is false");
- if (bufferedIn == null)
- bufferedIn = new BufferedInputStream(sock.getInputStream());
+ getHttpHeaders();
return bufferedIn;
}
@@ -247,6 +258,9 @@
boolean gotnl = false;
byte[] ch = new byte[1];
ch[0] = (byte) '\n';
+
+ boolean isFirst=true;
+
while (true)
{
// Check for leftover byte from non-'\n' after a '\r'.
@@ -266,6 +280,25 @@
}
}
line = line + new String(buf, 0, i);
+
+ if (isFirst) // parse the status line
+ {
+ isFirst=false;
+
+ int space1=line.indexOf(' ');
+ if (space1<0)
+ continue;
+
+ int space2=line.indexOf(' ',space1+1);
+ if (space2<0)
+ continue;
+
+ String responseCodeStr=line.substring(space1+1,space2);
+ responseCode=(new Integer(responseCodeStr)).intValue();
+ responseMessage=line.substring(space2+1);
+ line="";
+ continue;
+ }
// A '\r' '\n' combo indicates the end of the header entry.
// If it wasn't found, cycle back through the loop and append
--
/==============================================================\
|John Stracke | http://www.ecal.com |My opinions are my own.|
|Chief Scientist |=============================================|
|eCal Corp. |Never underestimate the power of human |
|francis@ecal.com|stupidity. --I forget who |
\==============================================================/