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]

Patch: FYI: two http protocol fixes


I'm checking this in on the 4.1 branch.

I won't put it on the trunk for now; instead I'll push this into
Classpath shortly.

We weren't properly handling redirect responses from the http server.
What happens is that we reuse the connection but fail to flush the
response body from the redirect itself, leading to a protocol error.

This patch fixes the problem by reading and discarding the response
body.

Tom

Index: classpath/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* gnu/java/net/protocol/http/HTTPURLConnection.java (connect):
	Read response body for redirect.

Index: classpath/gnu/java/net/protocol/http/HTTPURLConnection.java
===================================================================
--- classpath/gnu/java/net/protocol/http/HTTPURLConnection.java	(revision 109835)
+++ classpath/gnu/java/net/protocol/http/HTTPURLConnection.java	(working copy)
@@ -1,5 +1,5 @@
 /* HTTPURLConnection.java --
-   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -256,6 +256,22 @@
         
         if (response.getCodeClass() == 3 && getInstanceFollowRedirects())
           {
+	    // Read the response body, if there is one.  If the
+	    // redirect points us back at the same server, we will use
+	    // the cached connection, so we must make sure there is no
+	    // pending data in it.
+            InputStream body = response.getBody();
+	    if (body != null)
+	      {
+		byte[] ignore = new byte[1024];
+		while (true)
+		  {
+		    int n = body.read(ignore, 0, ignore.length);
+		    if (n == -1)
+		      break;
+		  }
+	      }
+
             // Follow redirect
             String location = response.getHeader("Location");
 	    if (location != null)


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