From 6bd59ffe1cffc84052ababe67f62b3a84753a5bc Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 1 May 2015 13:35:25 +0200 Subject: [PATCH] backported #848 --- plugins/transformation_gzip/gzip.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/transformation_gzip/gzip.c b/plugins/transformation_gzip/gzip.c index 645c7736..a340e33c 100644 --- a/plugins/transformation_gzip/gzip.c +++ b/plugins/transformation_gzip/gzip.c @@ -23,6 +23,12 @@ static int transform_gzip(struct wsgi_request *wsgi_req, struct uwsgi_transforma struct uwsgi_transformation_gzip *utgz = (struct uwsgi_transformation_gzip *) ut->data; struct uwsgi_buffer *ub = ut->chunk; + if (ub->pos == 0) { + // Don't try to compress empty responses. + free(utgz); + return 0; + } + if (ut->is_final) { if (uwsgi_gzip_fix(&utgz->z, utgz->crc32, ub, utgz->len)) { free(utgz); @@ -39,7 +45,7 @@ static int transform_gzip(struct wsgi_request *wsgi_req, struct uwsgi_transforma uwsgi_buffer_map(ub, gzipped, dlen); if (!utgz->header) { // do not check for errors !!! - uwsgi_response_add_header(wsgi_req, "Content-Encoding", 16, "gzip", 4); + uwsgi_response_add_header(wsgi_req, "Content-Encoding", 16, "gzip", 4); utgz->header = 1; if (uwsgi_buffer_insert(ub, 0, gzheader, 10)) { return -1; @@ -59,7 +65,7 @@ static int uwsgi_routing_func_gzip(struct wsgi_request *wsgi_req, struct uwsgi_r ut->can_stream = 1; // this is the trasformation clearing the memory ut = uwsgi_add_transformation(wsgi_req, transform_gzip, utgz); - ut->is_final = 1; + ut->is_final = 1; return UWSGI_ROUTE_NEXT; }