# HG changeset patch # User Igor Sysoev # Date 1095618420 0 # Node ID 1fa5daf7558ecfd4a6d05d62108080756a7d34d2 # Parent 694cd6cdb714aa788db769a3362bb7fa6b7b63ad nginx-0.0.11-2004-09-19-22:27:00 import diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -67,6 +67,7 @@ ngx_int_t ngx_output_chain(ngx_output_ch "zero size buf"); ctx->in = ctx->in->next; + continue; } @@ -146,6 +147,7 @@ ngx_int_t ngx_output_chain(ngx_output_ch if (out) { break; } + return rc; } diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -51,9 +51,11 @@ typedef struct { unsigned flush:4; unsigned redo:1; + unsigned done:1; +#if 0 unsigned pass:1; - unsigned done:1; unsigned blocked:1; +#endif size_t zin; size_t zout; @@ -445,8 +447,10 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9)); - ngx_test_null(ctx->preallocated, ngx_palloc(r->pool, ctx->allocated), - NGX_ERROR); + if (!(ctx->preallocated = ngx_palloc(r->pool, ctx->allocated))) { + return NGX_ERROR; + } + ctx->free_mem = ctx->preallocated; ctx->zstream.zalloc = ngx_http_gzip_filter_alloc; @@ -462,7 +466,9 @@ static ngx_int_t ngx_http_gzip_body_filt return ngx_http_gzip_error(ctx); } - ngx_test_null(b, ngx_calloc_buf(r->pool), ngx_http_gzip_error(ctx)); + if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) { + return ngx_http_gzip_error(ctx); + } b->memory = 1; b->pos = gzheader; @@ -488,7 +494,7 @@ static ngx_int_t ngx_http_gzip_body_filt for ( ;; ) { - /* is there a data to gzip ? */ + /* does zlib need a new data ? */ if (ctx->zstream.avail_in == 0 && ctx->flush == Z_NO_FLUSH @@ -519,6 +525,7 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->done = 1; return NGX_ERROR; } + /**/ if (ctx->in_buf->last_buf) { ctx->flush = Z_FINISH; @@ -538,28 +545,37 @@ static ngx_int_t ngx_http_gzip_body_filt } } + /* is there a space for the gzipped data ? */ if (ctx->zstream.avail_out == 0) { + if (ctx->free) { ctx->out_buf = ctx->free->buf; ctx->free = ctx->free->next; } else if (ctx->bufs < conf->bufs.num) { - ngx_test_null(ctx->out_buf, - ngx_create_temp_buf(r->pool, conf->bufs.size), - ngx_http_gzip_error(ctx)); + ctx->out_buf = ngx_create_temp_buf(r->pool, + conf->bufs.size); + if (ctx->out_buf == NULL) { + return ngx_http_gzip_error(ctx); + } + ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module; ctx->out_buf->recycled = 1; ctx->bufs++; } else { +#if 0 ctx->blocked = 1; +#endif break; } +#if 0 ctx->blocked = 0; +#endif ctx->zstream.next_out = ctx->out_buf->pos; ctx->zstream.avail_out = conf->bufs.size; } @@ -571,6 +587,7 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->flush, ctx->redo); rc = deflate(&ctx->zstream, ctx->flush); + 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); @@ -599,10 +616,14 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->out_buf->last = ctx->zstream.next_out; if (ctx->zstream.avail_out == 0) { + + /* zlib wants to output some more gzipped data */ + ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; + ctx->redo = 1; continue; @@ -611,6 +632,7 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->redo = 0; if (ctx->flush == Z_SYNC_FLUSH) { + ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; @@ -618,7 +640,10 @@ static ngx_int_t ngx_http_gzip_body_filt ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; + +#if 0 ctx->pass = 1; +#endif break; } @@ -629,6 +654,7 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->zout = 10 + ctx->zstream.total_out + 8; rc = deflateEnd(&ctx->zstream); + if (rc != Z_OK) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "deflateEnd() failed: %d", rc); @@ -648,8 +674,9 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->out_buf->last_buf = 1; } else { - ngx_test_null(b, ngx_create_temp_buf(r->pool, 8), - ngx_http_gzip_error(ctx)); + if (!(b = ngx_create_temp_buf(r->pool, 8))) { + return ngx_http_gzip_error(ctx); + } b->last_buf = 1; @@ -680,7 +707,9 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->zstream.avail_out = 0; ctx->done = 1; +#if 0 ctx->pass = 1; +#endif break; } @@ -690,12 +719,19 @@ static ngx_int_t ngx_http_gzip_body_filt ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; + +#if 0 ctx->pass = 1; +#endif break; } } +#if 0 + + /* OLD CODE */ + if (ctx->out) { if (ctx->pass) { ctx->pass = 0; @@ -704,6 +740,11 @@ static ngx_int_t ngx_http_gzip_body_filt return last; } + } else if (ctx->busy->buf && ngx_buf_size(ctx->busy->buf)) { + if (last != NGX_NONE) { + return last; + } + } else if (ctx->blocked) { if (last != NGX_NONE) { return last; @@ -716,9 +757,27 @@ static ngx_int_t ngx_http_gzip_body_filt return last; } +#endif + + /* NEW CODE */ + + if (last == NGX_AGAIN) { + return NGX_AGAIN; + } + + if (ctx->out == NULL && ctx->busy == NULL) { + return NGX_OK; + } + + /**/ last = ngx_http_next_body_filter(r, ctx->out); + /* + * we do not check NGX_AGAIN here because the downstream filters + * may free some buffers and zlib may compress some data into them + */ + if (last == NGX_ERROR) { return ngx_http_gzip_error(ctx); } @@ -873,22 +932,22 @@ static void *ngx_http_gzip_create_conf(n { ngx_http_gzip_conf_t *conf; - ngx_test_null(conf, - ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)), - NGX_CONF_ERROR); + if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) { + return NGX_CONF_ERROR; + } - /* set by ngx_pcalloc(): + /* + + set by ngx_pcalloc(): conf->bufs.num = 0; conf->proxied = 0; - */ - + */ conf->enable = NGX_CONF_UNSET; conf->no_buffer = NGX_CONF_UNSET; - conf->http_version = NGX_CONF_UNSET_UINT; conf->level = NGX_CONF_UNSET; @@ -933,16 +992,14 @@ static char *ngx_http_gzip_set_window(ng int wbits, wsize; + wbits = 15; -ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np); - - wbits = 15; for (wsize = 32 * 1024; wsize > 256; wsize >>= 1) { if (wsize == *np) { *np = wbits; -ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "WBITS: %d", *np); - return NULL; + + return NGX_CONF_OK; } wbits--; @@ -958,16 +1015,14 @@ static char *ngx_http_gzip_set_hash(ngx_ int memlevel, hsize; + memlevel = 9; -ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np); - - memlevel = 9; for (hsize = 128 * 1024; hsize > 256; hsize >>= 1) { if (hsize == *np) { *np = memlevel; -ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "MEMLEVEL: %d", *np); - return NULL; + + return NGX_CONF_OK; } memlevel--; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1153,7 +1153,7 @@ static ngx_int_t ngx_http_process_reques if (!r->headers_in.msie && !r->headers_in.opera) { - if (ngx_strstr(user_agent, "Gecko")) { + if (ngx_strstr(user_agent, "Gecko/")) { r->headers_in.gecko = 1; } else if (ngx_strstr(user_agent, "Konqueror")) {