From efafa79db5da5759a6c6550d2798193dbd55f243 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Thu, 16 Aug 2012 22:35:19 +0200 Subject: [PATCH] - added a content-encoding: gzip to streamed http server responses - finish and close streamed http responses immediately - this applies only to the solr interface which should be much faster now! --- .../anomic/http/server/HTTPDFileHandler.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java index 2b923a0b6..af54670fa 100644 --- a/source/de/anomic/http/server/HTTPDFileHandler.java +++ b/source/de/anomic/http/server/HTTPDFileHandler.java @@ -874,12 +874,28 @@ public final class HTTPDFileHandler { requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, path.endsWith(".stream") ? "stream" : ""); //requestHeader.put(httpHeader.CONNECTION_PROP_INPUTSTREAM, body); //requestHeader.put(httpHeader.CONNECTION_PROP_OUTPUTSTREAM, out); + + // prepare response header ResponseHeader header = new ResponseHeader(200); header.put(HeaderFramework.CONTENT_TYPE, getMimeFromServlet(targetClass, requestHeader, args, "text/xml")); conProp.remove(HeaderFramework.CONNECTION_PROP_PERSISTENT); - HTTPDemon.sendRespondHeader(conProp, out, httpVersion, 200, header); - invokeServlet(targetClass, requestHeader, args, out); + final boolean zipContent = requestHeader.acceptGzip(); + if (zipContent) header.put(HeaderFramework.CONTENT_ENCODING, "gzip"); + + // send response head + HTTPDemon.sendRespondHeader(conProp, out, httpVersion, 200, null, header); forceConnectionClose(conProp); + + // send response content + OutputStream o = zipContent ? new GZIPOutputStream(out) : out; + invokeServlet(targetClass, requestHeader, args, o); + + // immediately close stream as this terminates the http transmission + if (o instanceof GZIPOutputStream) ((GZIPOutputStream) o).finish(); + o.flush(); + o.close(); + out.flush(); + out.close(); return; } else if (targetFile.exists() && targetFile.isFile() && targetFile.canRead()) { // we have found a file that can be written to the client @@ -1305,7 +1321,7 @@ public final class HTTPDFileHandler { private static final void forceConnectionClose(final HashMap conprop) { if (conprop != null) { - conprop.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close"); + conprop.put(HeaderFramework.CONNECTION_PROP_PERSISTENT, "close"); } }