Author: nextgens
Date: 2007-04-02 17:46:42 +0000 (Mon, 02 Apr 2007)
New Revision: 12525
Modified:
trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
Log:
Allow plugins to send HTTP redirects
Modified: trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-04-02
14:40:36 UTC (rev 12524)
+++ trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-04-02
17:46:42 UTC (rev 12525)
@@ -71,10 +71,15 @@
writeReply(ctx, 200, "text/html", "OK",
pm.handleHTTPPost(plugin, request));
}
- catch(PluginHTTPException e)
+ catch(PluginHTTPException ex)
{
// TODO: make it into html
- writeReply(ctx, e.getCode(), e.getMimeType(),
e.getDesc(), e.getReply());
+ if((ex.getCode() < 400) && (ex.getCode() >=
300)) {
+ headers = new MultiValueTable();
+ headers.put("Location", ex.getReply());
+ ctx.sendReplyHeaders(ex.getCode(),
"Found", headers, null, 0);
+ }else
+ writeReply(ctx, ex.getCode(),
ex.getMimeType(), ex.getDesc(), ex.getReply());
}
catch(Throwable t)
{
@@ -196,9 +201,7 @@
// Plugin may need to know where it was
accessed from, so it can e.g. produce relative URLs.
//writeReply(ctx, 200, "text/html", "OK",
mkPage("plugin", pm.handleHTTPGet(plugin, data)));
- writeReply(ctx, 200, "text/html", "OK",
pm.handleHTTPGet(plugin, request));
-
-
+ writeReply(ctx, 200, "text/html", "OK",
pm.handleHTTPGet(plugin, request));
}
//FetchResult result = fetch(key);
@@ -206,7 +209,12 @@
} catch (PluginHTTPException ex) {
// TODO: make it into html
- writeReply(ctx, ex.getCode(), ex.getMimeType(),
ex.getDesc(), ex.getReply());
+ if((ex.getCode() < 400) && (ex.getCode() >= 300)) {
+ MultiValueTable headers = new MultiValueTable();
+ headers.put("Location", ex.getReply());
+ ctx.sendReplyHeaders(ex.getCode(), "Found",
headers, null, 0);
+ }else
+ writeReply(ctx, ex.getCode(), ex.getMimeType(),
ex.getDesc(), ex.getReply());
} catch (Throwable t) {
Logger.error(this, "Caught "+t, t);
String msg = "<html><head><title>Internal
Error</title></head><body><h1>Internal Error: please report</h1><pre>";