aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c124
1 files changed, 7 insertions, 117 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index e4c343c9b..48f3dd7c7 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -55,44 +55,23 @@ typedef struct {
unsigned redo:1;
unsigned done:1;
unsigned nomem:1;
- unsigned gzheader:1;
unsigned buffering:1;
unsigned intel:1;
size_t zin;
size_t zout;
- uint32_t crc32;
z_stream zstream;
ngx_http_request_t *request;
} ngx_http_gzip_ctx_t;
-#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
-
-struct gztrailer {
- uint32_t crc32;
- uint32_t zlen;
-};
-
-#else /* NGX_HAVE_BIG_ENDIAN || !NGX_HAVE_NONALIGNED */
-
-struct gztrailer {
- u_char crc32[4];
- u_char zlen[4];
-};
-
-#endif
-
-
static void ngx_http_gzip_filter_memory(ngx_http_request_t *r,
ngx_http_gzip_ctx_t *ctx);
static ngx_int_t ngx_http_gzip_filter_buffer(ngx_http_gzip_ctx_t *ctx,
ngx_chain_t *in);
static ngx_int_t ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
ngx_http_gzip_ctx_t *ctx);
-static ngx_int_t ngx_http_gzip_filter_gzheader(ngx_http_request_t *r,
- ngx_http_gzip_ctx_t *ctx);
static ngx_int_t ngx_http_gzip_filter_add_data(ngx_http_request_t *r,
ngx_http_gzip_ctx_t *ctx);
static ngx_int_t ngx_http_gzip_filter_get_buf(ngx_http_request_t *r,
@@ -446,12 +425,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return ctx->busy ? NGX_AGAIN : NGX_OK;
}
- if (!ctx->gzheader) {
- if (ngx_http_gzip_filter_gzheader(r, ctx) != NGX_OK) {
- goto failed;
- }
- }
-
rc = ngx_http_next_body_filter(r, ctx->out);
if (rc == NGX_ERROR) {
@@ -643,7 +616,7 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
ctx->zstream.opaque = ctx;
rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED,
- - ctx->wbits, ctx->memlevel, Z_DEFAULT_STRATEGY);
+ ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY);
if (rc != Z_OK) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
@@ -652,7 +625,6 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
}
ctx->last_out = &ctx->out;
- ctx->crc32 = crc32(0L, Z_NULL, 0);
ctx->flush = Z_NO_FLUSH;
return NGX_OK;
@@ -660,38 +632,6 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
static ngx_int_t
-ngx_http_gzip_filter_gzheader(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
-{
- ngx_buf_t *b;
- ngx_chain_t *cl;
- static u_char gzheader[10] =
- { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
-
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->memory = 1;
- b->pos = gzheader;
- b->last = b->pos + 10;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
- cl->next = ctx->out;
- ctx->out = cl;
-
- ctx->gzheader = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
{
ngx_chain_t *cl;
@@ -743,14 +683,9 @@ ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
} else if (ctx->in_buf->flush) {
ctx->flush = Z_SYNC_FLUSH;
- }
-
- if (ctx->zstream.avail_in) {
- ctx->crc32 = crc32(ctx->crc32, ctx->zstream.next_in,
- ctx->zstream.avail_in);
-
- } else if (ctx->flush == Z_NO_FLUSH) {
+ } else if (ctx->zstream.avail_in == 0) {
+ /* ctx->flush == Z_NO_FLUSH */
return NGX_AGAIN;
}
@@ -932,13 +867,11 @@ static ngx_int_t
ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
ngx_http_gzip_ctx_t *ctx)
{
- int rc;
- ngx_buf_t *b;
- ngx_chain_t *cl;
- struct gztrailer *trailer;
+ int rc;
+ ngx_chain_t *cl;
ctx->zin = ctx->zstream.total_in;
- ctx->zout = 10 + ctx->zstream.total_out + 8;
+ ctx->zout = ctx->zstream.total_out;
rc = deflateEnd(&ctx->zstream);
@@ -960,50 +893,7 @@ ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
*ctx->last_out = cl;
ctx->last_out = &cl->next;
- if (ctx->zstream.avail_out >= 8) {
- trailer = (struct gztrailer *) ctx->out_buf->last;
- ctx->out_buf->last += 8;
- ctx->out_buf->last_buf = 1;
-
- } else {
- b = ngx_create_temp_buf(r->pool, 8);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last_buf = 1;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
- cl->next = NULL;
- *ctx->last_out = cl;
- ctx->last_out = &cl->next;
- trailer = (struct gztrailer *) b->pos;
- b->last += 8;
- }
-
-#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
-
- trailer->crc32 = ctx->crc32;
- trailer->zlen = ctx->zin;
-
-#else
-
- trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff);
- trailer->crc32[1] = (u_char) ((ctx->crc32 >> 8) & 0xff);
- trailer->crc32[2] = (u_char) ((ctx->crc32 >> 16) & 0xff);
- trailer->crc32[3] = (u_char) ((ctx->crc32 >> 24) & 0xff);
-
- trailer->zlen[0] = (u_char) (ctx->zin & 0xff);
- trailer->zlen[1] = (u_char) ((ctx->zin >> 8) & 0xff);
- trailer->zlen[2] = (u_char) ((ctx->zin >> 16) & 0xff);
- trailer->zlen[3] = (u_char) ((ctx->zin >> 24) & 0xff);
-
-#endif
+ ctx->out_buf->last_buf = 1;
ctx->zstream.avail_in = 0;
ctx->zstream.avail_out = 0;