Author: toad
Date: 2007-09-08 18:19:40 +0000 (Sat, 08 Sep 2007)
New Revision: 15070
Modified:
trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
trunk/freenet/src/freenet/clients/http/ToadletContext.java
trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
Log:
Disconnect after handling a throwable from a plugin
Modified: trunk/freenet/src/freenet/clients/http/PproxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-09-08
18:02:20 UTC (rev 15069)
+++ trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-09-08
18:19:40 UTC (rev 15070)
@@ -241,6 +241,7 @@
} catch(PluginHTTPException e) {
sendErrorPage(ctx, PluginHTTPException.code, e.message,
e.location);
} catch (Throwable t) {
+ ctx.forceDisconnect();
writeInternalError(t, ctx);
}
}
Modified: trunk/freenet/src/freenet/clients/http/ToadletContext.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ToadletContext.java 2007-09-08
18:02:20 UTC (rev 15069)
+++ trunk/freenet/src/freenet/clients/http/ToadletContext.java 2007-09-08
18:19:40 UTC (rev 15070)
@@ -29,6 +29,13 @@
void writeData(byte[] data, int offset, int length) throws
ToadletContextClosedException, IOException;
/**
+ * Force a disconnection after handling this request. Used only when a
throwable was thrown and we don't know
+ * what the state of the connection is. FIXME we could handle this
better by remembering whether headers have
+ * been sent, how long the attached data should be, how much data has
been sent etc.
+ */
+ void forceDisconnect();
+
+ /**
* Convenience method that simply calls {@link #writeData(byte[], int,
int)}.
*
* @param data
Modified: trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
2007-09-08 18:02:20 UTC (rev 15069)
+++ trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
2007-09-08 18:19:40 UTC (rev 15070)
@@ -270,10 +270,10 @@
headers.put(before, after);
}
- boolean shouldDisconnect =
shouldDisconnectAfterHandled(split[2].equals("HTTP/1.0"), headers);
+ boolean disconnect =
shouldDisconnectAfterHandled(split[2].equals("HTTP/1.0"), headers);
ToadletContextImpl ctx = new
ToadletContextImpl(sock, headers, container.getCSSName(), bf, pageMaker,
container);
- ctx.shouldDisconnect = shouldDisconnect;
+ ctx.shouldDisconnect = disconnect;
/*
* if we're handling a POST, copy the data into
a bucket now,
@@ -313,7 +313,7 @@
Toadlet t = container.findToadlet(uri);
if(t == null) {
-
ctx.sendNoToadletError(shouldDisconnect);
+
ctx.sendNoToadletError(ctx.shouldDisconnect);
break;
}
@@ -346,11 +346,11 @@
}
} else {
-
ctx.sendMethodNotAllowed(method, shouldDisconnect);
+
ctx.sendMethodNotAllowed(method, ctx.shouldDisconnect);
ctx.close();
}
}
- if(shouldDisconnect) {
+ if(ctx.shouldDisconnect) {
sock.close();
return;
}
@@ -438,4 +438,8 @@
public boolean doRobots() {
return container.doRobots();
}
+
+ public void forceDisconnect() {
+ this.shouldDisconnect = true;
+ }
}