diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-04-21 18:54:33 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-21 18:54:33 +0000 |
| commit | 732a27196381164c799d345ec0d010b416408555 (patch) | |
| tree | 043848398927223e1b08d1b15c071b3a23717d76 /src/http | |
| parent | bb570859043557c5c1b20d933ff2e4c18d13c980 (diff) | |
| download | nginx-732a27196381164c799d345ec0d010b416408555.tar.gz nginx-732a27196381164c799d345ec0d010b416408555.tar.bz2 | |
nginx-0.0.3-2004-04-21-22:54:33 import
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 156 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.c | 35 | ||||
| -rw-r--r-- | src/http/ngx_http_core_module.h | 1 | ||||
| -rw-r--r-- | src/http/ngx_http_parse.c | 4 | ||||
| -rw-r--r-- | src/http/ngx_http_request.c | 12 | ||||
| -rw-r--r-- | src/http/ngx_http_special_response.c | 6 |
6 files changed, 142 insertions, 72 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index a4b154b74..3b228c47b 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -495,6 +495,9 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) && ctx->flush == Z_NO_FLUSH && !ctx->redo) { + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "gzip in: " PTR_FMT, ctx->in); + if (ctx->in == NULL) { break; } @@ -505,6 +508,18 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->zstream.next_in = ctx->in_hunk->pos; ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "gzip in_hunk:" PTR_FMT " ni:" PTR_FMT " ai:%d", + ctx->in_hunk, + ctx->zstream.next_in, ctx->zstream.avail_in); + + /* STUB */ + if (ctx->in_hunk->last < ctx->in_hunk->pos) { + ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, + "zstream.avail_in is huge"); + return NGX_ERROR; + } + if (ctx->in_hunk->type & NGX_HUNK_LAST) { ctx->flush = Z_FINISH; @@ -547,11 +562,11 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->zstream.avail_out = conf->bufs.size; } - ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d", + ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d redo:%d", ctx->zstream.next_in, ctx->zstream.next_out, ctx->zstream.avail_in, ctx->zstream.avail_out, - ctx->flush); + ctx->flush, ctx->redo); rc = deflate(&ctx->zstream, ctx->flush); if (rc != Z_OK && rc != Z_STREAM_END) { @@ -566,6 +581,10 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->zstream.avail_in, ctx->zstream.avail_out, rc); + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "gzip in_hunk:" PTR_FMT " pos:" PTR_FMT, + ctx->in_hunk, ctx->in_hunk->pos); + ctx->in_hunk->pos = ctx->zstream.next_in; ctx->out_hunk->last = ctx->zstream.next_out; @@ -576,95 +595,112 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->last_out = &cl->next; ctx->redo = 1; - } else { - ctx->redo = 0; + continue; + } - if (ctx->flush == Z_SYNC_FLUSH) { - ctx->out_hunk->type |= NGX_HUNK_FLUSH; - ctx->flush = Z_NO_FLUSH; + ctx->redo = 0; - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); - *ctx->last_out = cl; - ctx->last_out = &cl->next; + if (ctx->flush == Z_SYNC_FLUSH) { + ctx->out_hunk->type |= NGX_HUNK_FLUSH; + ctx->flush = Z_NO_FLUSH; - break; + ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, + ngx_http_gzip_error(ctx)); + *ctx->last_out = cl; + ctx->last_out = &cl->next; - } else if (ctx->flush == Z_FINISH) { + break; + } - /* rc == Z_STREAM_END */ + if (ctx->flush == Z_FINISH) { - ctx->zin = ctx->zstream.total_in; - ctx->zout = 10 + ctx->zstream.total_out + 8; + /* rc == Z_STREAM_END */ - rc = deflateEnd(&ctx->zstream); - if (rc != Z_OK) { - ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, - "deflateEnd() failed: %d", rc); - return ngx_http_gzip_error(ctx); - } + ctx->zin = ctx->zstream.total_in; + ctx->zout = 10 + ctx->zstream.total_out + 8; - ngx_pfree(r->pool, ctx->preallocated); + rc = deflateEnd(&ctx->zstream); + if (rc != Z_OK) { + ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, + "deflateEnd() failed: %d", rc); + return ngx_http_gzip_error(ctx); + } - ctx->flush = Z_NO_FLUSH; + ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); - *ctx->last_out = cl; - ctx->last_out = &cl->next; + ctx->flush = Z_NO_FLUSH; - if (ctx->zstream.avail_out >= 8) { - trailer = (struct gztrailer *) ctx->out_hunk->last; - ctx->out_hunk->type |= NGX_HUNK_LAST; - ctx->out_hunk->last += 8; + ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, + ngx_http_gzip_error(ctx)); + *ctx->last_out = cl; + ctx->last_out = &cl->next; - } else { - ngx_test_null(h, - ngx_create_temp_hunk(r->pool, 8), - ngx_http_gzip_error(ctx)); + if (ctx->zstream.avail_out >= 8) { + trailer = (struct gztrailer *) ctx->out_hunk->last; + ctx->out_hunk->type |= NGX_HUNK_LAST; + ctx->out_hunk->last += 8; - h->type |= NGX_HUNK_LAST; + } else { + ngx_test_null(h, ngx_create_temp_hunk(r->pool, 8), + ngx_http_gzip_error(ctx)); - ngx_alloc_link_and_set_hunk(cl, h, r->pool, - ngx_http_gzip_error(ctx)); - *ctx->last_out = cl; - ctx->last_out = &cl->next; - trailer = (struct gztrailer *) h->pos; - h->last += 8; - } + h->type |= NGX_HUNK_LAST; + + ngx_alloc_link_and_set_hunk(cl, h, r->pool, + ngx_http_gzip_error(ctx)); + *ctx->last_out = cl; + ctx->last_out = &cl->next; + trailer = (struct gztrailer *) h->pos; + h->last += 8; + } #if (HAVE_LITTLE_ENDIAN) - trailer->crc32 = ctx->crc32; - trailer->zlen = ctx->zin; + trailer->crc32 = ctx->crc32; + trailer->zlen = ctx->zin; #else - /* STUB */ Oops ! + /* STUB */ Oops ! #endif - ctx->zstream.avail_in = 0; - ctx->zstream.avail_out = 0; + ctx->zstream.avail_in = 0; + ctx->zstream.avail_out = 0; - ctx->done = 1; + ctx->done = 1; #if 0 - ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); + ngx_http_delete_ctx(r, ngx_http_gzip_filter_module); #endif - break; + break; + } - } else if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); - *ctx->last_out = cl; - ctx->last_out = &cl->next; + if (conf->no_buffer && ctx->in == NULL) { + ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, + ngx_http_gzip_error(ctx)); + *ctx->last_out = cl; + ctx->last_out = &cl->next; - break; - } + break; } } + if (ctx->out) { + if (last == NGX_AGAIN) { + return last; + } + + } else { + if (last == NGX_NONE) { + return NGX_OK; + } + + return last; + } + +#if 0 if (ctx->out == NULL && last != NGX_NONE) { return last; } +#endif last = ngx_http_next_body_filter(r, ctx->out); diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 51fda1a4a..3128a76f1 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1449,7 +1449,8 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *lcf = conf; - ngx_uint_t i; + int overwrite; + ngx_uint_t i, n; ngx_str_t *value; ngx_http_err_page_t *err; @@ -1463,8 +1464,35 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) value = cf->args->elts; - for (i = 1; i < cf->args->nelts - 1; i++) { - ngx_test_null(err, ngx_push_array(lcf->error_pages), NGX_CONF_ERROR); + i = cf->args->nelts - 2; + + if (value[i].data[0] == '=') { + if (i == 1) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid value \"%s\"", value[i].data); + return NGX_CONF_ERROR; + } + + overwrite = ngx_atoi(&value[i].data[1], value[i].len - 1); + + if (overwrite == NGX_ERROR) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid value \"%s\"", value[i].data); + return NGX_CONF_ERROR; + } + + n = 2; + + } else { + overwrite = 0; + n = 1; + } + + for (i = 1; i < cf->args->nelts - n; i++) { + if (!(err = ngx_push_array(lcf->error_pages))) { + return NGX_CONF_ERROR; + } + err->code = ngx_atoi(value[i].data, value[i].len); if (err->code == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, @@ -1479,6 +1507,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } + err->overwrite = overwrite; err->uri = value[cf->args->nelts - 1]; } diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 130106bae..661fcafbf 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -106,6 +106,7 @@ typedef struct { typedef struct { int code; + int overwrite; ngx_str_t uri; } ngx_http_err_page_t; diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index 33bc23759..381ee57e0 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -46,6 +46,10 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r) case sw_start: r->request_start = p - 1; + if (ch == CR || ch == LF) { + break; + } + if (ch < 'A' || ch > 'Z') { return NGX_HTTP_PARSE_INVALID_METHOD; } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 30b3e597e..1697eefae 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -728,8 +728,10 @@ static void ngx_http_process_request_headers(ngx_event_t *rev) /* there was error while a header line parsing */ -#if (NGX_LOG_DEBUG) - if (rc == NGX_HTTP_PARSE_INVALID_HEADER) { +#if (NGX_DEBUG) + if (rc == NGX_HTTP_PARSE_INVALID_HEADER + && (rev->log->log_level & NGX_LOG_DEBUG_HTTP)) + { u_char *p; for (p = r->header_name_start; p < r->header_in->last - 1; @@ -1249,12 +1251,6 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r) wev->event_handler = ngx_http_empty_handler; - /* skip the tralling "\r\n" before the possible pipelined request */ - - while (h->pos < h->last && (*h->pos == CR || *h->pos == LF)) { - h->pos++; - } - if (h->pos < h->last) { /* diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 275ae95c9..4eb8899de 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -214,7 +214,11 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) err_page = clcf->error_pages->elts; for (i = 0; i < clcf->error_pages->nelts; i++) { if (err_page[i].code == error) { - r->err_status = error; + if (err_page[i].overwrite) { + r->err_status = err_page[i].overwrite; + } else { + r->err_status = error; + } r->err_ctx = r->ctx; return ngx_http_internal_redirect(r, &err_page[i].uri, NULL); } |
