From 35da156ad2950779a2eb1fd1f43d65a0976a8646 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 16 Nov 2013 20:24:56 +0200 Subject: [PATCH] WebUI: Don't gzip too small payloads. --- src/webui/httpresponsegenerator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/webui/httpresponsegenerator.cpp b/src/webui/httpresponsegenerator.cpp index 91d15c28b..69cb6e76e 100644 --- a/src/webui/httpresponsegenerator.cpp +++ b/src/webui/httpresponsegenerator.cpp @@ -119,7 +119,11 @@ bool HttpResponseGenerator::gCompress(QByteArray &dest_buffer) { } QByteArray HttpResponseGenerator::toByteArray() { - if (m_gzip && m_message.size() > 0) {// prevents writing a useless and wasteful header + // A gzip seems to have 23 bytes overhead. + // Also "content-encoding: gzip\r\n" is 26 bytes long + // So we only benefit from gzip if the message is bigger than 23+26 = 49 + // If the message is smaller than 49 bytes we actually send MORE data if we gzip + if (m_gzip && m_message.size() > 49) { QByteArray dest_buf; if (gCompress(dest_buf)) { setValue("content-encoding", "gzip");