From ba736ab81caf69c26ce8c23319ddfc3327341d3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 6 Sep 2013 07:04:18 +0200 Subject: [PATCH] Close output stream before sending the page to the browser. --- .../pterodactylus/sone/web/page/PageToadlet.java | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java index 2c6706f..a40a543 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java +++ b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java @@ -18,12 +18,14 @@ package net.pterodactylus.sone.web.page; import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import net.pterodactylus.util.web.Header; import net.pterodactylus.util.web.Method; import net.pterodactylus.util.web.Page; import net.pterodactylus.util.web.Response; + import freenet.client.HighLevelSimpleClient; import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.LinkFilterExceptedToadlet; @@ -144,21 +146,28 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback, LinkFil */ private void handleRequest(FreenetRequest pageRequest) throws IOException, ToadletContextClosedException { Bucket pageBucket = null; + OutputStream pageBucketOutputStream = null; + Response pageResponse; try { pageBucket = pageRequest.getToadletContext().getBucketFactory().makeBucket(-1); - Response pageResponse = new Response(pageBucket.getOutputStream()); - pageResponse = page.handleRequest(pageRequest, pageResponse); - MultiValueTable headers = new MultiValueTable(); - if (pageResponse.getHeaders() != null) { - for (Header header : pageResponse.getHeaders()) { - for (String value : header) { - headers.put(header.getName(), value); - } + pageBucketOutputStream = pageBucket.getOutputStream(); + pageResponse = page.handleRequest(pageRequest, new Response(pageBucketOutputStream)); + } catch (IOException ioe1) { + Closer.close(pageBucket); + throw ioe1; + } finally { + Closer.close(pageBucketOutputStream); + } + MultiValueTable headers = new MultiValueTable(); + if (pageResponse.getHeaders() != null) { + for (Header header : pageResponse.getHeaders()) { + for (String value : header) { + headers.put(header.getName(), value); } } + } + try { writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, pageBucket); - } catch (Throwable t1) { - writeInternalError(t1, pageRequest.getToadletContext()); } finally { Closer.close(pageBucket); } -- 2.7.4