Commit 51282cea by Chris Burdess Committed by Michael Koch

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
parent 465ee71e
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.
2005-04-27 Sven de Marothy <sven@physto.se> 2005-04-27 Sven de Marothy <sven@physto.se>
* java/util/TimeZone.java, * java/util/TimeZone.java,
......
...@@ -40,6 +40,7 @@ package gnu.java.net.protocol.http; ...@@ -40,6 +40,7 @@ package gnu.java.net.protocol.http;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
...@@ -94,6 +95,7 @@ public class HTTPURLConnection ...@@ -94,6 +95,7 @@ public class HTTPURLConnection
private Response response; private Response response;
private ByteArrayInputStream responseSink; private ByteArrayInputStream responseSink;
private ByteArrayInputStream errorSink;
private HandshakeCompletedEvent handshakeEvent; private HandshakeCompletedEvent handshakeEvent;
...@@ -281,11 +283,32 @@ public class HTTPURLConnection ...@@ -281,11 +283,32 @@ public class HTTPURLConnection
file = location.substring(end); file = location.substring(end);
retry = true; 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 else
{ {
responseSink = new ByteArrayInputStream(reader.toByteArray ()); responseSink = new ByteArrayInputStream(reader.toByteArray ());
if (response.getCode() == 404)
{
errorSink = responseSink;
throw new FileNotFoundException(url.toString());
}
} }
} }
while (retry); while (retry);
...@@ -455,6 +478,11 @@ public class HTTPURLConnection ...@@ -455,6 +478,11 @@ public class HTTPURLConnection
return responseSink; return responseSink;
} }
public InputStream getErrorStream()
{
return errorSink;
}
public Map getHeaderFields() public Map getHeaderFields()
{ {
if (!connected) if (!connected)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment