For HTTP URLs that return response code 302 (Moved Temporarily), URL.openStream should follow the redirect to the new location. Currently it returns null. For HTTP URLs that return response code 404 (Not Found), URL.openStream should raise a FileNotFoundException. Currently it returns a stream with the error document as if it received the response code 200 (OK).
The 30x redirect issue was explained a bit more on irc. What happens is that some servers just sent a absolutePath as Location: header while the spec says (and our code expects) a full absoluteUri. Proposed patch to be liberal in what we accept: 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 12:34:05 -0000 @@ -239,6 +239,13 @@ file = location.substring(start); retry = true; } + if (location.charAt(0) == '/') + { + // Location URLs should be full absoluteURIs, + // but in practise some servers send just an absolute path. + file = location; + retry = true; + } else if (location.startsWith("http:")) { connection.close(); The 40x transformation to FileNotFoundException looks strange to me. We do properly return the 404 when you ask for getResponseCode(). Then we do indeed return as InputStream the page that the server sends us. Maybe the behavior should different between uc.openConnection() and uc.openStream()?
Fixed by the following two changes: 2005-04-27 Chris Burdess <dog@gnu.org> * java/net/protocol/http/HTTPURLConnection.java (connect): Accept absolute and relative paths in Location header. 2005-04-26 Chris Burdess <dog@gnu.org> * gnu/java/net/protocol/http/HTTPURLConnection.java: Throw FileNotFoundException and implement getErrorStream on 404.