Mark Wielaard wrote:
As explained in [bug #12815] URL.openStream doesn't handle 302 and 404
HTTP response codes properly:
(http://savannah.gnu.org/bugs/?func=detailitem&item_id=12815)
For 30x redirects we expect (as the spec says) an absoluteUri as
Location header. Some servers sent just an absolute path
(Sun-ONE-Web-Server/6.1 for example) not a fill URI. Since our old code
accepted this I think we should be liberal in what we accept.

2005-04-26  Mark Wielaard  <[EMAIL PROTECTED]>

* java/net/protocol/http/HTTPURLConnection.java (connect): Accept
locations starting with '/' for CodeClass 3.

Chris, you wrote this code originally following the spec precisely. Do
you think this is a good patch/idea?

If we allow this, should we not also allow any relative URI?

I don't like this much, but if we are to accept malformed absolute URIs I feel strongly that we should at least report the event as a warning. This patch should accept the malformed URIs:

Index: gnu/java/net/protocol/http/HTTPURLConnection.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/http/ HTTPURLConnection.java,v
retrieving revision 1.6
diff -u -r1.6 HTTPURLConnection.java
--- gnu/java/net/protocol/http/HTTPURLConnection.java 2 Mar 2005 17:29:09 -0000 1.6
+++ gnu/java/net/protocol/http/HTTPURLConnection.java 26 Apr 2005 18:35:23 -0000
@@ -281,7 +281,23 @@
file = location.substring(end);
retry = true;
}
- // Otherwise this is not an HTTP redirect, can't follow
+ else if (location.length() > 0)
+ {
+ // Malformed absolute URI, treat as file part of URI
+ if (location.charAt(0) == '/')
+ {
+ // Absolute path
+ file = location;
+ }
+ else
+ {
+ // Relative path
+ int lsi = file.lastIndexOf('/');
+ file = (lsi == -1) ? "/" : file.substring(0, lsi + 1);
+ file += location;
+ }
+ retry = true;
+ }
}
else
{



Do we have a standard mechanism for reporting warning conditions? Is System.err.println acceptable?

I haven't yet looked into the second part of that bug report (throwing
FileNotFoundException on 404 handling).

I suggest the following patch to implement getErrorStream correctly:

2005-04-26  Chris Burdess  <[EMAIL PROTECTED]>

        * gnu/java/net/protocol/http/HTTPURLConnection.java: Throw
        FileNotFoundException and implement getErrorStream on 404.

--
Chris Burdess

Attachment: patch
Description: Binary data

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to