diff options
author | Chris Burdess <dog@gnu.org> | 2005-04-27 18:57:02 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2005-04-27 18:57:02 +0000 |
commit | 51282ceaf054c617c4a5e0d7f2458c39637d2566 (patch) | |
tree | 0566c2174e9e0c3723a146c7c44e27f3928e5bb3 /libjava/gnu/java | |
parent | 465ee71e97935394f5aafbe32ae9b6f3f3ecb434 (diff) | |
download | gcc-51282ceaf054c617c4a5e0d7f2458c39637d2566.zip gcc-51282ceaf054c617c4a5e0d7f2458c39637d2566.tar.gz gcc-51282ceaf054c617c4a5e0d7f2458c39637d2566.tar.bz2 |
HTTPURLConnection.java (connect): Accept absolute and relative paths in Location header.
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-27 Chris Burdess <dog@gnu.org>
* gnu/java/net/protocol/http/HTTPURLConnection.java: Throw
FileNotFoundException and implement getErrorStream on 404.
From-SVN: r98875
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r-- | libjava/gnu/java/net/protocol/http/HTTPURLConnection.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java b/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java index 2938dfc..50a6ed1 100644 --- a/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java +++ b/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java @@ -40,6 +40,7 @@ package gnu.java.net.protocol.http; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -94,6 +95,7 @@ public class HTTPURLConnection private Response response; private ByteArrayInputStream responseSink; + private ByteArrayInputStream errorSink; private HandshakeCompletedEvent handshakeEvent; @@ -281,11 +283,32 @@ public class HTTPURLConnection 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 { responseSink = new ByteArrayInputStream(reader.toByteArray ()); + if (response.getCode() == 404) + { + errorSink = responseSink; + throw new FileNotFoundException(url.toString()); + } } } while (retry); @@ -455,6 +478,11 @@ public class HTTPURLConnection return responseSink; } + public InputStream getErrorStream() + { + return errorSink; + } + public Map getHeaderFields() { if (!connected) |