Changeset 4468:93dd50a9dc70 in nginx


Ignore:
Timestamp:
02/13/12 15:23:43 (8 years ago)
Author:
Maxim Dounin <mdounin@…>
Branch:
default
Phase:
public
Convert:
svn:c3fe7df1-7212-e011-8a91-001109144009/trunk@4469
Message:

Gzip filter: handling of empty flush buffers.

Empty flush buffers are legitimate and may happen e.g. due to $r->flush()
calls in embedded perl. If there are no data buffered in zlib, deflate()
will return Z_BUF_ERROR (i.e. no progress possible) without adding anything
to output. Don't treat Z_BUF_ERROR as fatal and correctly send empty flush
buffer if we have no data in output at all.

See this thread for details:
http://mailman.nginx.org/pipermail/nginx/2010-November/023693.html

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/http/modules/ngx_http_gzip_filter_module.c

    r4412 r4468  
    760760{
    761761    int                    rc;
     762    ngx_buf_t             *b;
    762763    ngx_chain_t           *cl;
    763764    ngx_http_gzip_conf_t  *conf;
     
    771772    rc = deflate(&ctx->zstream, ctx->flush);
    772773
    773     if (rc != Z_OK && rc != Z_STREAM_END) {
     774    if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) {
    774775        ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
    775776                      "deflate() failed: %d, %d", ctx->flush, rc);
     
    820821    if (ctx->flush == Z_SYNC_FLUSH) {
    821822
    822         ctx->zstream.avail_out = 0;
    823         ctx->out_buf->flush = 1;
    824823        ctx->flush = Z_NO_FLUSH;
    825824
     
    829828        }
    830829
    831         cl->buf = ctx->out_buf;
     830        b = ctx->out_buf;
     831
     832        if (ngx_buf_size(b) == 0) {
     833
     834            b = ngx_calloc_buf(ctx->request->pool);
     835            if (b == NULL) {
     836                return NGX_ERROR;
     837            }
     838
     839        } else {
     840            ctx->zstream.avail_out = 0;
     841        }
     842
     843        b->flush = 1;
     844
     845        cl->buf = b;
    832846        cl->next = NULL;
    833847        *ctx->last_out = cl;
Note: See TracChangeset for help on using the changeset viewer.