diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-05-28 15:49:23 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-05-28 15:49:23 +0000 |
| commit | 369145cef1971e4273dc59340689c2d96f84d18a (patch) | |
| tree | 55f59267d9ada5160ad74168bf5721ce5b3653ff /src/http/modules | |
| parent | 87a7d1c44917e352e336c859c2a797e5d60b19da (diff) | |
| download | nginx-369145cef1971e4273dc59340689c2d96f84d18a.tar.gz nginx-369145cef1971e4273dc59340689c2d96f84d18a.tar.bz2 | |
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_charset_filter.c | 12 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_chunked_filter.c | 47 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 98 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 60 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 22 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 2 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 111 |
7 files changed, 178 insertions, 174 deletions
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index b31166efe..279001baf 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -40,7 +40,7 @@ typedef struct { } ngx_http_charset_ctx_t; -static void ngx_charset_recode(ngx_hunk_t *h, char *table); +static void ngx_charset_recode(ngx_buf_t *b, char *table); static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -50,7 +50,7 @@ static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name); -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle); static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf); static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf); @@ -212,18 +212,18 @@ static int ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in) table = charsets[lcf->source_charset].tables[lcf->default_charset]; for (cl = in; cl; cl = cl->next) { - ngx_charset_recode(cl->hunk, table); + ngx_charset_recode(cl->buf, table); } return ngx_http_next_body_filter(r, in); } -static void ngx_charset_recode(ngx_hunk_t *h, char *table) +static void ngx_charset_recode(ngx_buf_t *b, char *table) { u_char *p, c; - for (p = h->pos; p < h->last; p++) { + for (p = b->pos; p < b->last; p++) { c = *p; *p = table[c]; } @@ -412,7 +412,7 @@ static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name) } -static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) +static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle) { ngx_http_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_charset_header_filter; diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index 70e0fcd4f..c429fa881 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -58,14 +58,14 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { u_char *chunk; size_t size, len; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t out, tail, *cl, *tl, **ll; if (in == NULL || !r->chunked) { return ngx_http_next_body_filter(r, in); } - out.hunk = NULL; + out.buf = NULL; ll = &out.next; size = 0; @@ -73,12 +73,12 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http chunk: %d", ngx_hunk_size(cl->hunk)); + "http chunk: %d", ngx_buf_size(cl->buf)); - size += ngx_hunk_size(cl->hunk); + size += ngx_buf_size(cl->buf); ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - tl->hunk = cl->hunk; + tl->buf = cl->buf; *ll = tl; ll = &tl->next; @@ -93,25 +93,26 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->pos = chunk; - h->last = chunk + len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->pos = chunk; + b->last = chunk + len; - out.hunk = h; + out.buf = b; } - if (cl->hunk->type & NGX_HUNK_LAST) { - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; - h->pos = (u_char *) CRLF "0" CRLF CRLF; - h->last = h->pos + 7; + if (cl->buf->last_buf) { + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->last_buf = 1; + b->pos = (u_char *) CRLF "0" CRLF CRLF; + b->last = b->pos + 7; - cl->hunk->type &= ~NGX_HUNK_LAST; + cl->buf->last_buf = 0; if (size == 0) { - h->pos += 2; - out.hunk = h; + b->pos += 2; + out.buf = b; out.next = NULL; return ngx_http_next_body_filter(r, &out); @@ -123,13 +124,13 @@ static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) return ngx_http_next_body_filter(r, out.next); } - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = (u_char *) CRLF; - h->last = h->pos + 2; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->pos = (u_char *) CRLF; + b->last = b->pos + 2; } - tail.hunk = h; + tail.buf = b; tail.next = NULL; *ll = &tail; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index 76b07bfb5..4f43f3464 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -39,9 +39,9 @@ typedef struct { ngx_chain_t *busy; ngx_chain_t *out; ngx_chain_t **last_out; - ngx_hunk_t *in_hunk; - ngx_hunk_t *out_hunk; - ngx_int_t hunks; + ngx_buf_t *in_buf; + ngx_buf_t *out_buf; + ngx_int_t bufs; off_t length; @@ -407,7 +407,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { int rc, wbits, memlevel, last; struct gztrailer *trailer; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *cl; ngx_http_gzip_ctx_t *ctx; ngx_http_gzip_conf_t *conf; @@ -465,13 +465,13 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) return ngx_http_gzip_error(ctx); } - ngx_test_null(h, ngx_calloc_hunk(r->pool), ngx_http_gzip_error(ctx)); + ngx_test_null(b, ngx_calloc_buf(r->pool), ngx_http_gzip_error(ctx)); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = gzheader; - h->last = h->pos + 10; + b->memory = 1; + b->pos = gzheader; + b->last = b->pos + 10; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); ctx->out = cl; ctx->last_out = &cl->next; @@ -504,29 +504,29 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) break; } - ctx->in_hunk = ctx->in->hunk; + ctx->in_buf = ctx->in->buf; ctx->in = ctx->in->next; - ctx->zstream.next_in = ctx->in_hunk->pos; - ctx->zstream.avail_in = ctx->in_hunk->last - ctx->in_hunk->pos; + ctx->zstream.next_in = ctx->in_buf->pos; + ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->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, + "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", + ctx->in_buf, ctx->zstream.next_in, ctx->zstream.avail_in); /* STUB */ - if (ctx->in_hunk->last < ctx->in_hunk->pos) { + 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_hunk->type & NGX_HUNK_LAST) { + if (ctx->in_buf->last_buf) { ctx->flush = Z_FINISH; - } else if (ctx->in_hunk->type & NGX_HUNK_FLUSH) { + } else if (ctx->in_buf->flush) { ctx->flush = Z_SYNC_FLUSH; } @@ -545,17 +545,17 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) if (ctx->zstream.avail_out == 0) { if (ctx->free) { - ctx->out_hunk = ctx->free->hunk; + ctx->out_buf = ctx->free->buf; ctx->free = ctx->free->next; - } else if (ctx->hunks < conf->bufs.num) { - ngx_test_null(ctx->out_hunk, - ngx_create_temp_hunk(r->pool, conf->bufs.size), - ngx_http_gzip_error(ctx)); - ctx->out_hunk->tag = (ngx_hunk_tag_t) + } 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->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module; - ctx->out_hunk->type |= NGX_HUNK_RECYCLED; - ctx->hunks++; + ctx->out_buf->recycled = 1; + ctx->bufs++; } else { ctx->blocked = 1; @@ -563,7 +563,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } ctx->blocked = 0; - ctx->zstream.next_out = ctx->out_hunk->pos; + ctx->zstream.next_out = ctx->out_buf->pos; ctx->zstream.avail_out = conf->bufs.size; } @@ -587,23 +587,23 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 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); + "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, + ctx->in_buf, ctx->in_buf->pos); if (ctx->zstream.next_in) { - ctx->in_hunk->pos = ctx->zstream.next_in; + ctx->in_buf->pos = ctx->zstream.next_in; if (ctx->zstream.avail_in == 0) { ctx->zstream.next_in = NULL; } } - ctx->out_hunk->last = ctx->zstream.next_out; + ctx->out_buf->last = ctx->zstream.next_out; if (ctx->zstream.avail_out == 0) { - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + 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; @@ -614,11 +614,11 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ctx->redo = 0; if (ctx->flush == Z_SYNC_FLUSH) { - ctx->out_hunk->type |= NGX_HUNK_FLUSH; + ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + 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->pass = 1; @@ -640,28 +640,28 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + 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; 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; + trailer = (struct gztrailer *) ctx->out_buf->last; + ctx->out_buf->last += 8; + ctx->out_buf->last_buf = 1; } else { - ngx_test_null(h, ngx_create_temp_hunk(r->pool, 8), + ngx_test_null(b, ngx_create_temp_buf(r->pool, 8), ngx_http_gzip_error(ctx)); - h->type |= NGX_HUNK_LAST; + b->last_buf = 1; - ngx_alloc_link_and_set_hunk(cl, h, r->pool, - ngx_http_gzip_error(ctx)); + ngx_alloc_link_and_set_buf(cl, b, r->pool, + ngx_http_gzip_error(ctx)); *ctx->last_out = cl; ctx->last_out = &cl->next; - trailer = (struct gztrailer *) h->pos; - h->last += 8; + trailer = (struct gztrailer *) b->pos; + b->last += 8; } #if (HAVE_LITTLE_ENDIAN) @@ -681,8 +681,8 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_hunk(cl, ctx->out_hunk, r->pool, - ngx_http_gzip_error(ctx)); + 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->pass = 1; @@ -719,7 +719,7 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out, - (ngx_hunk_tag_t) &ngx_http_gzip_filter_module); + (ngx_buf_tag_t) &ngx_http_gzip_filter_module); ctx->last_out = &ctx->out; if (ctx->done) { diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index ecb42ad3d..484bcb07b 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -406,7 +406,7 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_uint_t i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -417,18 +417,15 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, /* * the optimized version for the static files only - * that are passed in the single file hunk + * that are passed in the single file buf */ - if (in - && in->hunk->type & NGX_HUNK_FILE - && in->hunk->type & NGX_HUNK_LAST) - { + if (in && in->buf->in_file && in->buf->last_buf) { range = r->headers_out.ranges.elts; if (r->headers_out.ranges.nelts == 1) { - in->hunk->file_pos = range->start; - in->hunk->file_last = range->end; + in->buf->file_pos = range->start; + in->buf->file_last = range->end; return ngx_http_next_body_filter(r, in); } @@ -446,33 +443,33 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, * "Content-Range: bytes " */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; - h->pos = ctx->boundary_header.data; - h->last = ctx->boundary_header.data + ctx->boundary_header.len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->memory = 1; + b->pos = ctx->boundary_header.data; + b->last = ctx->boundary_header.data + ctx->boundary_header.len; ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - hcl->hunk = h; + hcl->buf = b; /* "SSSS-EEEE/TTTT" CRLF CRLF */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; - h->pos = range[i].content_range.data; - h->last = range[i].content_range.data + range[i].content_range.len; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->pos = range[i].content_range.data; + b->last = range[i].content_range.data + range[i].content_range.len; ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); - rcl->hunk = h; + rcl->buf = b; /* the range data */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_FILE; - h->file_pos = range[i].start; - h->file_last = range[i].end; - h->file = in->hunk->file; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->in_file = 1; + b->file_pos = range[i].start; + b->file_last = range[i].end; + b->file = in->buf->file; - ngx_alloc_link_and_set_hunk(dcl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR); *ll = hcl; hcl->next = rcl; @@ -482,14 +479,15 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, /* the last boundary CRLF "--0123456789--" CRLF */ - ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); - h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP|NGX_HUNK_LAST; - ngx_test_null(h->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); - h->last = ngx_cpymem(h->pos, ctx->boundary_header.data, 4 + 10); - *h->last++ = '-'; *h->last++ = '-'; - *h->last++ = CR; *h->last++ = LF; + ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + b->temporary = 1; + b->last_buf = 1; + ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); + b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10); + *b->last++ = '-'; *b->last++ = '-'; + *b->last++ = CR; *b->last++ = LF; - ngx_alloc_link_and_set_hunk(hcl, h, r->pool, NGX_ERROR); + ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR); *ll = hcl; return ngx_http_next_body_filter(r, out); diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index d06113b8a..532e8faab 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -67,7 +67,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) ngx_str_t name, location; ngx_err_t err; ngx_log_t *log; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t out; ngx_file_info_t fi; ngx_http_cleanup_t *file_cleanup, *redirect_cleanup; @@ -472,11 +472,11 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) /* we need to allocate all before the header would be sent */ - if (!(h = ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)))) { + if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - if (!(h->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) { + if (!(b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -487,15 +487,19 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) return rc; } - h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST; + b->in_file = 1; - h->file_pos = 0; - h->file_last = ngx_file_size(&fi); + if (!r->main) { + b->last_buf = 1; + } + + b->file_pos = 0; + b->file_last = ngx_file_size(&fi); - h->file->fd = fd; - h->file->log = log; + b->file->fd = fd; + b->file->log = log; - out.hunk = h; + out.buf = b; out.next = NULL; return ngx_http_output_filter(r, &out); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index e0f85ee20..c89e971dc 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -159,7 +159,7 @@ struct ngx_http_proxy_ctx_s { ngx_http_proxy_upstream_t *upstream; ngx_http_proxy_cache_t *cache; - ngx_hunk_t *header_in; + ngx_buf_t *header_in; ngx_http_busy_lock_ctx_t busy_lock; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 60c9e8fca..ed25c8e11 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -108,7 +108,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) { size_t len; ngx_uint_t i; - ngx_hunk_t *h; + ngx_buf_t *b; ngx_chain_t *chain; ngx_table_elt_t *header; ngx_http_request_t *r; @@ -177,71 +177,73 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) len += header[i].key.len + 2 + header[i].value.len + 2; } - /* STUB */ len++; +#if (NGX_DEBUG) + len++; +#endif - ngx_test_null(h, ngx_create_temp_hunk(r->pool, len), NULL); - ngx_alloc_link_and_set_hunk(chain, h, r->pool, NULL); + ngx_test_null(b, ngx_create_temp_buf(r->pool, len), NULL); + ngx_alloc_link_and_set_buf(chain, b, r->pool, NULL); /* the request line */ if (p->upstream->method) { - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, http_methods[p->upstream->method - 1].data, http_methods[p->upstream->method - 1].len); } else { - h->last = ngx_cpymem(h->last, r->method_name.data, r->method_name.len); + b->last = ngx_cpymem(b->last, r->method_name.data, r->method_name.len); } - h->last = ngx_cpymem(h->last, uc->uri.data, uc->uri.len); + b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len); - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, r->uri.data + uc->location->len, r->uri.len - uc->location->len); if (r->args.len > 0) { - *(h->last++) = '?'; - h->last = ngx_cpymem(h->last, r->args.data, r->args.len); + *(b->last++) = '?'; + b->last = ngx_cpymem(b->last, r->args.data, r->args.len); } - h->last = ngx_cpymem(h->last, http_version, sizeof(http_version) - 1); + b->last = ngx_cpymem(b->last, http_version, sizeof(http_version) - 1); /* the "Connection: close" header */ - h->last = ngx_cpymem(h->last, connection_close_header, + b->last = ngx_cpymem(b->last, connection_close_header, sizeof(connection_close_header) - 1); /* the "Host" header */ - h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1); + b->last = ngx_cpymem(b->last, host_header, sizeof(host_header) - 1); if (p->lcf->preserve_host && r->headers_in.host) { - h->last = ngx_cpymem(h->last, r->headers_in.host->value.data, + b->last = ngx_cpymem(b->last, r->headers_in.host->value.data, r->headers_in.host_name_len); if (!uc->default_port) { - *(h->last++) = ':'; - h->last = ngx_cpymem(h->last, uc->port_text.data, + *(b->last++) = ':'; + b->last = ngx_cpymem(b->last, uc->port_text.data, uc->port_text.len); } } else { - h->last = ngx_cpymem(h->last, uc->host_header.data, + b->last = ngx_cpymem(b->last, uc->host_header.data, uc->host_header.len); } - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; /* the "X-Real-IP" header */ if (p->lcf->set_x_real_ip) { - h->last = ngx_cpymem(h->last, x_real_ip_header, + b->last = ngx_cpymem(b->last, x_real_ip_header, sizeof(x_real_ip_header) - 1); - h->last = ngx_cpymem(h->last, r->connection->addr_text.data, + b->last = ngx_cpymem(b->last, r->connection->addr_text.data, r->connection->addr_text.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } @@ -249,23 +251,23 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) if (p->lcf->add_x_forwarded_for) { if (r->headers_in.x_forwarded_for) { - h->last = ngx_cpymem(h->last, x_forwarded_for_header, + b->last = ngx_cpymem(b->last, x_forwarded_for_header, sizeof(x_forwarded_for_header) - 1); - h->last = ngx_cpymem(h->last, + b->last = ngx_cpymem(b->last, r->headers_in.x_forwarded_for->value.data, r->headers_in.x_forwarded_for->value.len); - *(h->last++) = ','; *(h->last++) = ' '; + *(b->last++) = ','; *(b->last++) = ' '; } else { - h->last = ngx_cpymem(h->last, x_forwarded_for_header, + b->last = ngx_cpymem(b->last, x_forwarded_for_header, sizeof(x_forwarded_for_header) - 1); } - h->last = ngx_cpymem(h->last, r->connection->addr_text.data, + b->last = ngx_cpymem(b->last, r->connection->addr_text.data, r->connection->addr_text.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; } @@ -289,14 +291,14 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) continue; } - h->last = ngx_cpymem(h->last, header[i].key.data, header[i].key.len); + b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); - *(h->last++) = ':'; *(h->last++) = ' '; + *(b->last++) = ':'; *(b->last++) = ' '; - h->last = ngx_cpymem(h->last, header[i].value.data, + b->last = ngx_cpymem(b->last, header[i].value.data, header[i].value.len); - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http proxy header: \"%s: %s\"", @@ -304,12 +306,12 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) } /* add "\r\n" at the header end */ - *(h->last++) = CR; *(h->last++) = LF; + *(b->last++) = CR; *(b->last++) = LF; #if (NGX_DEBUG) - *(h->last) = '\0'; + *(b->last) = '\0'; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http proxy header:\n\"%s\"", h->pos); + "http proxy header:\n\"%s\"", b->pos); #endif return chain; @@ -389,7 +391,7 @@ static void ngx_http_proxy_init_upstream(void *data) output->sendfile = r->sendfile; output->pool = r->pool; output->bufs.num = 1; - output->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; output->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer; if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) { @@ -420,15 +422,15 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p) /* reinit the request chain */ for (cl = p->request->request_body->bufs; cl; cl = cl->next) { - cl->hunk->pos = cl->hunk->start; - cl->hunk->file_pos = 0; + cl->buf->pos = cl->buf->start; + cl->buf->file_pos = 0; } /* reinit the ngx_output_chain() context */ output = p->upstream->output_chain_ctx; - output->hunk = NULL; + output->buf = NULL; output->in = NULL; output->free = NULL; output->busy = NULL; @@ -614,9 +616,9 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) return; } - output->free->hunk = r->request_body->buf; - output->free->next = NULL; - output->hunks = 1; + output->free->buf = r->request_body->buf; + output->free->buf = NULL; + output->allocated = 1; r->request_body->buf->pos = r->request_body->buf->start; } @@ -793,13 +795,13 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev) } if (p->header_in == NULL) { - p->header_in = ngx_create_temp_hunk(p->request->pool, - p->lcf->header_buffer_size); + p->header_in = ngx_create_temp_buf(p->request->pool, + p->lcf->header_buffer_size); if (p->header_in == NULL) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); return; } - p->header_in->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + p->header_in->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; if (p->cache) { p->header_in->pos += p->cache->ctx.header_size; @@ -1176,7 +1178,7 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) ep->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; ep->output_ctx = r; - ep->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; + ep->tag = (ngx_buf_tag_t) &ngx_http_proxy_module; ep->bufs = p->lcf->bufs; ep->busy_size = p->lcf->busy_buffers_size; ep->upstream = p->upstream->peer.connection; @@ -1206,25 +1208,24 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) ep->max_temp_file_size = p->lcf->max_temp_file_size; ep->temp_file_write_size = p->lcf->temp_file_write_size; - ep->preread_hunks = ngx_alloc_chain_link(r->pool); - if (ep->preread_hunks == NULL) { + if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) { ngx_http_proxy_finalize_request(p, 0); return; } - ep->preread_hunks->hunk = p->header_in; - ep->preread_hunks->next = NULL; + ep->preread_bufs->buf = p->header_in; + ep->preread_bufs->next = NULL; ep->preread_size = p->header_in->last - p->header_in->pos; if (p->cachable) { - ep->hunk_to_file = ngx_calloc_hunk(r->pool); - if (ep->hunk_to_file == NULL) { + ep->buf_to_file = ngx_calloc_buf(r->pool); + if (ep->buf_to_file == NULL) { ngx_http_proxy_finalize_request(p, 0); return; } - ep->hunk_to_file->pos = p->header_in->start; - ep->hunk_to_file->last = p->header_in->pos; - ep->hunk_to_file->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + ep->buf_to_file->pos = p->header_in->start; + ep->buf_to_file->last = p->header_in->pos; + ep->buf_to_file->temporary = 1; } if (ngx_event_flags & NGX_USE_AIO_EVENT) { @@ -1232,7 +1233,7 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) ep->single_buf = 1; } - /* TODO: ep->free_bufs = 0 if use ngx_create_chain_of_hunks() */ + /* TODO: ep->free_bufs = 0 if use ngx_create_chain_of_bufs() */ ep->free_bufs = 1; /* |
