From 3d9ee8107aed4978ccd3bd48addea79b420af48b Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 3 Sep 2004 00:50:19 +0000 Subject: [PATCH] support for HTTP 3xx redirects darcs-hash:20040903005019-5007d-9c8b15091c6bf87ae3c8848273a8c0f4e36bd458.gz --- src/org/ibex/net/HTTP.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/org/ibex/net/HTTP.java b/src/org/ibex/net/HTTP.java index c95183c..69f54cd 100644 --- a/src/org/ibex/net/HTTP.java +++ b/src/org/ibex/net/HTTP.java @@ -16,8 +16,9 @@ public class HTTP { public static InetAddress originAddr = null; public static String originHost = null; - // FIXME: HACK + // FIXME: HACK: these shouldn't be set globally public static String userAgent = "Ibex"; + public static boolean allowRedirects = true; // Cookies ////////////////////////////////////////////////////////////////////////////// @@ -200,6 +201,15 @@ public class HTTP { releaseMe.release(); return makeRequest(contentType, content, referer, cookies); + } else if (reply.startsWith("3") && allowRedirects) { + String location = (String)h.get("location"); + if (location == null) throw new HTTPException("Got HTTP " + reply.substring(0, 3) + " but no Location header"); + Log.info(HTTP.class, "redirecting to " + location); + if (content != null) + return new HTTP(location).POST(contentType, content, url, cookies); + else + return new HTTP(location).GET(url, cookies); + } else if (reply.startsWith("2")) { if (h.get("HTTP").equals("1.0") && h.get("content-length") == null) throw new HTTPException("Ibex does not support HTTP/1.0 servers which fail to return the Content-Length header"); -- 1.7.10.4