55 static void *ngx_http_gunzip_filter_alloc(
void *opaque, u_int items,
57 static void ngx_http_gunzip_filter_free(
void *opaque,
void *address);
60 static void *ngx_http_gunzip_create_conf(
ngx_conf_t *cf);
61 static char *ngx_http_gunzip_merge_conf(
ngx_conf_t *cf,
62 void *parent,
void *child);
87 ngx_http_gunzip_filter_init,
95 ngx_http_gunzip_create_conf,
96 ngx_http_gunzip_merge_conf
102 &ngx_http_gunzip_filter_module_ctx,
103 ngx_http_gunzip_filter_commands,
136 (u_char *)
"gzip", 4) != 0)
138 return ngx_http_next_header_filter(r);
143 if (!r->gzip_tested) {
144 if (ngx_http_gzip_ok(r) ==
NGX_OK) {
145 return ngx_http_next_header_filter(r);
148 }
else if (r->gzip_ok) {
149 return ngx_http_next_header_filter(r);
170 return ngx_http_next_header_filter(r);
183 if (ctx == NULL || ctx->
done) {
184 return ngx_http_next_body_filter(r, in);
188 "http gunzip filter");
191 if (ngx_http_gunzip_filter_inflate_start(r, ctx) !=
NGX_OK) {
206 if (ngx_http_next_body_filter(r, NULL) ==
NGX_ERROR) {
225 rc = ngx_http_gunzip_filter_add_data(r, ctx);
238 rc = ngx_http_gunzip_filter_get_buf(r, ctx);
248 rc = ngx_http_gunzip_filter_inflate(r, ctx);
261 if (ctx->
out == NULL) {
265 rc = ngx_http_next_body_filter(r, ctx->
out);
276 "gunzip out: %p", ctx->
out);
304 ctx->
zstream.zalloc = ngx_http_gunzip_filter_alloc;
305 ctx->
zstream.zfree = ngx_http_gunzip_filter_free;
309 rc = inflateInit2(&ctx->
zstream, MAX_WBITS + 16);
313 "inflateInit2() failed: %d", rc);
320 ctx->
flush = Z_NO_FLUSH;
335 "gunzip in: %p", ctx->
in);
337 if (ctx->
in == NULL) {
348 "gunzip in_buf:%p ni:%p ai:%ud",
353 ctx->
flush = Z_FINISH;
356 ctx->
flush = Z_SYNC_FLUSH;
358 }
else if (ctx->
zstream.avail_in == 0) {
417 "inflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
424 if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) {
426 "inflate() failed: %d, %d", ctx->
flush, rc);
431 "inflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
437 "gunzip in_buf:%p pos:%p",
443 if (ctx->
zstream.avail_in == 0) {
450 if (ctx->
zstream.avail_out == 0) {
471 if (ctx->
flush == Z_SYNC_FLUSH) {
473 ctx->
flush = Z_NO_FLUSH;
503 if (rc == Z_STREAM_END && ctx->
flush == Z_FINISH
507 if (ngx_http_gunzip_filter_inflate_end(r, ctx) !=
NGX_OK) {
514 if (rc == Z_STREAM_END && ctx->
zstream.avail_in > 0) {
516 rc = inflateReset(&ctx->
zstream);
520 "inflateReset() failed: %d", rc);
529 if (ctx->
in == NULL) {
565 "gunzip inflate end");
567 rc = inflateEnd(&ctx->
zstream);
571 "inflateEnd() failed: %d", rc);
606 ngx_http_gunzip_filter_alloc(
void *opaque, u_int items, u_int size)
611 "gunzip alloc: n:%ud s:%ud",
619 ngx_http_gunzip_filter_free(
void *opaque,
void *address)
625 "gunzip free: %p", address);
653 ngx_http_gunzip_merge_conf(
ngx_conf_t *cf,
void *parent,
void *child)