From: David ‘Bombe’ Roden Date: Fri, 6 Sep 2013 05:04:18 +0000 (+0200) Subject: Close output stream before sending the page to the browser. X-Git-Tag: 0.8.7^2~25 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ba736ab81caf69c26ce8c23319ddfc3327341d3c;p=Sone.git Close output stream before sending the page to the browser. --- 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); }