[Patch] gnu.java.net.protocol.http.HTTPURLConnection
Michael Koch
konqueror@gmx.de
Wed Apr 27 18:58:00 GMT 2005
Hi list,
I just commited the attached patch to merge the latest two fixes for
gnu.java.net.protocol.http.HTTPURLConnection from GNU classpath to HEAD.
Michael
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.
-------------- next part --------------
Index: gnu/java/net/protocol/http/HTTPURLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/net/protocol/http/HTTPURLConnection.java,v
retrieving revision 1.2
diff -u -r1.2 HTTPURLConnection.java
--- gnu/java/net/protocol/http/HTTPURLConnection.java 18 Apr 2005 18:40:23 -0000 1.2
+++ gnu/java/net/protocol/http/HTTPURLConnection.java 27 Apr 2005 18:56:36 -0000
@@ -40,6 +40,7 @@
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 @@
private Response response;
private ByteArrayInputStream responseSink;
+ private ByteArrayInputStream errorSink;
private HandshakeCompletedEvent handshakeEvent;
@@ -281,11 +283,32 @@
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 @@
return responseSink;
}
+ public InputStream getErrorStream()
+ {
+ return errorSink;
+ }
+
public Map getHeaderFields()
{
if (!connected)
More information about the Java-patches
mailing list