This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: two http protocol fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 20 Jan 2006 14:57:07 -0700
- Subject: Patch: FYI: two http protocol fixes
- Reply-to: tromey at redhat dot com
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)