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
This commit is contained in:
Shawn Pearce 2015-07-17 15:07:58 -07:00
parent 14a6afd561
commit 920d3cbea6

View File

@ -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;