mirror of
https://github.com/nginx/nginx.git
synced 2025-08-06 06:46:16 +08:00
*) split ngx_http_gzip_body_filter()
*) send gzheader together with the filter's first output
This commit is contained in:
parent
051d85f6b0
commit
3e8c2f7811
@ -48,6 +48,7 @@ typedef struct {
|
||||
unsigned redo:1;
|
||||
unsigned done:1;
|
||||
unsigned nomem:1;
|
||||
unsigned gzheader:1;
|
||||
|
||||
size_t zin;
|
||||
size_t zout;
|
||||
@ -58,10 +59,39 @@ typedef struct {
|
||||
} 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 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,
|
||||
ngx_http_gzip_ctx_t *ctx);
|
||||
static ngx_int_t ngx_http_gzip_filter_deflate(ngx_http_request_t *r,
|
||||
ngx_http_gzip_ctx_t *ctx);
|
||||
static ngx_int_t ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
|
||||
ngx_http_gzip_ctx_t *ctx);
|
||||
|
||||
static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
|
||||
u_int size);
|
||||
static void ngx_http_gzip_filter_free(void *opaque, void *address);
|
||||
static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx);
|
||||
|
||||
static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf);
|
||||
static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
|
||||
@ -177,25 +207,6 @@ ngx_module_t ngx_http_gzip_filter_module = {
|
||||
};
|
||||
|
||||
|
||||
static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
|
||||
|
||||
#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 ngx_str_t ngx_http_gzip_ratio = ngx_string("gzip_ratio");
|
||||
|
||||
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
||||
@ -262,12 +273,9 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
{
|
||||
int rc, wbits, memlevel;
|
||||
struct gztrailer *trailer;
|
||||
ngx_buf_t *b;
|
||||
int rc;
|
||||
ngx_chain_t *cl;
|
||||
ngx_http_gzip_ctx_t *ctx;
|
||||
ngx_http_gzip_conf_t *conf;
|
||||
|
||||
ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
|
||||
|
||||
@ -275,9 +283,130 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
return ngx_http_next_body_filter(r, in);
|
||||
}
|
||||
|
||||
if (ctx->preallocated == NULL) {
|
||||
if (ngx_http_gzip_filter_deflate_start(r, ctx) != NGX_OK) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (in) {
|
||||
if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->nomem) {
|
||||
|
||||
/* flush busy buffers */
|
||||
|
||||
if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
cl = NULL;
|
||||
|
||||
ngx_chain_update_chains(&ctx->free, &ctx->busy, &cl,
|
||||
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
||||
ctx->nomem = 0;
|
||||
}
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* cycle while we can write to a client */
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* cycle while there is data to feed zlib and ... */
|
||||
|
||||
rc = ngx_http_gzip_filter_add_data(r, ctx);
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc == NGX_AGAIN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* ... there are buffers to write zlib output */
|
||||
|
||||
rc = ngx_http_gzip_filter_get_buf(r, ctx);
|
||||
|
||||
if (rc == NGX_DECLINED) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
||||
rc = ngx_http_gzip_filter_deflate(r, ctx);
|
||||
|
||||
if (rc == NGX_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
/* rc == NGX_AGAIN */
|
||||
}
|
||||
|
||||
if (ctx->out == NULL) {
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
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) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
|
||||
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
||||
ctx->last_out = &ctx->out;
|
||||
|
||||
ctx->nomem = 0;
|
||||
|
||||
if (ctx->done) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* unreachable */
|
||||
|
||||
failed:
|
||||
|
||||
ctx->done = 1;
|
||||
|
||||
if (ctx->preallocated) {
|
||||
deflateEnd(&ctx->zstream);
|
||||
|
||||
ngx_pfree(r->pool, ctx->preallocated);
|
||||
}
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
|
||||
ngx_http_gzip_ctx_t *ctx)
|
||||
{
|
||||
int rc, wbits, memlevel;
|
||||
ngx_http_gzip_conf_t *conf;
|
||||
|
||||
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
||||
|
||||
if (ctx->preallocated == NULL) {
|
||||
wbits = conf->wbits;
|
||||
memlevel = conf->memlevel;
|
||||
|
||||
@ -294,8 +423,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
/*
|
||||
* We preallocate a memory for zlib in one buffer (200K-400K), this
|
||||
* decreases a number of malloc() and free() calls and also probably
|
||||
* decreases a number of syscalls (sbrk() and so on).
|
||||
* Besides we free this memory as soon as the gzipping will complete
|
||||
* decreases a number of syscalls (sbrk()/mmap() and so on).
|
||||
* Besides we free the memory as soon as a gzipping will complete
|
||||
* and do not wait while a whole response will be sent to a client.
|
||||
*
|
||||
* 8K is for zlib deflate_state, it takes
|
||||
@ -322,13 +451,29 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
if (rc != Z_OK) {
|
||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"deflateInit2() failed: %d", rc);
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
|
||||
|
||||
ctx->last_out = &ctx->out;
|
||||
ctx->crc32 = crc32(0L, Z_NULL, 0);
|
||||
ctx->flush = Z_NO_FLUSH;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
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_pcalloc(r->pool, sizeof(ngx_buf_t));
|
||||
if (b == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -338,59 +483,31 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cl->buf = b;
|
||||
cl->next = NULL;
|
||||
cl->next = ctx->out;
|
||||
ctx->out = cl;
|
||||
ctx->last_out = &cl->next;
|
||||
|
||||
r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
|
||||
ctx->gzheader = 1;
|
||||
|
||||
ctx->crc32 = crc32(0L, Z_NULL, 0);
|
||||
ctx->flush = Z_NO_FLUSH;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
||||
{
|
||||
if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
if (in) {
|
||||
if (ngx_chain_add_copy(r->pool, &ctx->in, in) == NGX_ERROR) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->nomem) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"gzip nomem");
|
||||
|
||||
if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cl = NULL;
|
||||
|
||||
ngx_chain_update_chains(&ctx->free, &ctx->busy, &cl,
|
||||
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
||||
ctx->nomem = 0;
|
||||
}
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
/* does zlib need a new data ? */
|
||||
|
||||
if (ctx->zstream.avail_in == 0
|
||||
&& ctx->flush == Z_NO_FLUSH
|
||||
&& !ctx->redo)
|
||||
{
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"gzip in: %p", ctx->in);
|
||||
|
||||
if (ctx->in == NULL) {
|
||||
break;
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
ctx->in_buf = ctx->in->buf;
|
||||
@ -404,15 +521,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
ctx->in_buf,
|
||||
ctx->zstream.next_in, ctx->zstream.avail_in);
|
||||
|
||||
/* STUB */
|
||||
if (ctx->in_buf->last < ctx->in_buf->pos) {
|
||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"zstream.avail_in is huge");
|
||||
ctx->done = 1;
|
||||
return NGX_ERROR;
|
||||
}
|
||||
/**/
|
||||
|
||||
if (ctx->in_buf->last_buf) {
|
||||
ctx->flush = Z_FINISH;
|
||||
|
||||
@ -420,47 +528,63 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
ctx->flush = Z_SYNC_FLUSH;
|
||||
}
|
||||
|
||||
if (ctx->zstream.avail_in == 0) {
|
||||
if (ctx->flush == Z_NO_FLUSH) {
|
||||
continue;
|
||||
}
|
||||
if (ctx->zstream.avail_in) {
|
||||
|
||||
} else {
|
||||
ctx->crc32 = crc32(ctx->crc32, ctx->zstream.next_in,
|
||||
ctx->zstream.avail_in);
|
||||
}
|
||||
|
||||
} else if (ctx->flush == Z_NO_FLUSH) {
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
/* is there a space for the gzipped data ? */
|
||||
|
||||
if (ctx->zstream.avail_out == 0) {
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
||||
{
|
||||
ngx_http_gzip_conf_t *conf;
|
||||
|
||||
if (ctx->zstream.avail_out) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
||||
|
||||
if (ctx->free) {
|
||||
ctx->out_buf = ctx->free->buf;
|
||||
ctx->free = ctx->free->next;
|
||||
|
||||
} else if (ctx->bufs < conf->bufs.num) {
|
||||
ctx->out_buf = ngx_create_temp_buf(r->pool,
|
||||
conf->bufs.size);
|
||||
|
||||
ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size);
|
||||
if (ctx->out_buf == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ctx->out_buf->tag = (ngx_buf_tag_t)
|
||||
&ngx_http_gzip_filter_module;
|
||||
ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module;
|
||||
ctx->out_buf->recycled = 1;
|
||||
ctx->bufs++;
|
||||
|
||||
} else {
|
||||
ctx->nomem = 1;
|
||||
break;
|
||||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
ctx->zstream.next_out = ctx->out_buf->pos;
|
||||
ctx->zstream.avail_out = conf->bufs.size;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_filter_deflate(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
|
||||
{
|
||||
int rc;
|
||||
ngx_chain_t *cl;
|
||||
ngx_http_gzip_conf_t *conf;
|
||||
|
||||
ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
|
||||
@ -473,7 +597,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
if (rc != Z_OK && rc != Z_STREAM_END) {
|
||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"deflate() failed: %d, %d", ctx->flush, rc);
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -487,7 +610,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
"gzip in_buf:%p pos:%p",
|
||||
ctx->in_buf, ctx->in_buf->pos);
|
||||
|
||||
|
||||
if (ctx->zstream.next_in) {
|
||||
ctx->in_buf->pos = ctx->zstream.next_in;
|
||||
|
||||
@ -504,7 +626,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -515,7 +636,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
ctx->redo = 1;
|
||||
|
||||
continue;
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
ctx->redo = 0;
|
||||
@ -528,7 +649,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -537,11 +657,48 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
*ctx->last_out = cl;
|
||||
ctx->last_out = &cl->next;
|
||||
|
||||
break;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
if (rc == Z_STREAM_END) {
|
||||
|
||||
if (ngx_http_gzip_filter_deflate_end(r, ctx) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
|
||||
|
||||
if (conf->no_buffer && ctx->in == NULL) {
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cl->buf = ctx->out_buf;
|
||||
cl->next = NULL;
|
||||
*ctx->last_out = cl;
|
||||
ctx->last_out = &cl->next;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
ctx->zin = ctx->zstream.total_in;
|
||||
ctx->zout = 10 + ctx->zstream.total_out + 8;
|
||||
|
||||
@ -550,7 +707,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
if (rc != Z_OK) {
|
||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"deflateEnd() failed: %d", rc);
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -558,7 +714,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -575,7 +730,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
} else {
|
||||
b = ngx_create_temp_buf(r->pool, 8);
|
||||
if (b == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -583,7 +737,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
@ -601,6 +754,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
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);
|
||||
@ -610,6 +764,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
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->zstream.avail_in = 0;
|
||||
@ -619,47 +774,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (conf->no_buffer && ctx->in == NULL) {
|
||||
|
||||
cl = ngx_alloc_chain_link(r->pool);
|
||||
if (cl == NULL) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cl->buf = ctx->out_buf;
|
||||
cl->next = NULL;
|
||||
*ctx->last_out = cl;
|
||||
ctx->last_out = &cl->next;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->out == NULL) {
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
rc = ngx_http_next_body_filter(r, ctx->out);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
ngx_http_gzip_error(ctx);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
|
||||
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
|
||||
ctx->last_out = &ctx->out;
|
||||
|
||||
ctx->nomem = 0;
|
||||
|
||||
if (ctx->done) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -717,24 +832,6 @@ ngx_http_gzip_filter_free(void *opaque, void *address)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx)
|
||||
{
|
||||
deflateEnd(&ctx->zstream);
|
||||
|
||||
if (ctx->preallocated) {
|
||||
ngx_pfree(ctx->request->pool, ctx->preallocated);
|
||||
}
|
||||
|
||||
ctx->zstream.avail_in = 0;
|
||||
ctx->zstream.avail_out = 0;
|
||||
|
||||
ctx->done = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_gzip_add_variables(ngx_conf_t *cf)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user