From 920d3cbea620abc6881414bdb196b65611874169 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 17 Jul 2015 15:07:58 -0700 Subject: [PATCH] RestApiServlet: Use Content-Length for very small replies If the reply is smaller than 256 bytes it should not be compressed. Return the original src object so the Content-Length property can be preserved and set onto the HTTP response. This allows small replies to use Content-Length instead of the much larger chunked transfer encoding. Change-Id: I04edc6e79fb61020e43e064151613ddc389a3bd2 --- .../java/com/google/gerrit/httpd/restapi/RestApiServlet.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index 66a9a82f74..44bf7aa6ba 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -826,7 +826,9 @@ public class RestApiServlet extends HttpServlet { final BinaryResult src) throws IOException { BinaryResult gz; long len = src.getContentLength(); - if (256 <= len && len <= (10 << 20)) { + if (len < 256) { + return src; // Do not compress very small payloads. + } else if (len <= (10 << 20)) { gz = compress(src); if (len <= gz.getContentLength()) { return src;