diff options
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_access_handler.c | 9 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_autoindex_handler.c | 24 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_charset_filter.c | 16 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_chunked_filter.c | 33 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_gzip_filter.c | 79 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_headers_filter.c | 6 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 18 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_not_modified_filter.c | 2 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_range_filter.c | 358 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_rewrite_handler.c | 22 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 17 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_status_handler.c | 10 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_userid_filter.c | 177 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_cache.c | 9 | ||||
| -rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 110 | ||||
| -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 | 34 |
17 files changed, 526 insertions, 400 deletions
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c index 3a323b149..9e5c43c4d 100644 --- a/src/http/modules/ngx_http_access_handler.c +++ b/src/http/modules/ngx_http_access_handler.c @@ -97,8 +97,9 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r) rule = alcf->rules->elts; for (i = 0; i < alcf->rules->nelts; i++) { -ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%08X %08X %08X", - addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "%08XD %08XD %08XD", + addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); if ((addr_in->sin_addr.s_addr & rule[i].mask) == rule[i].addr) { if (rule[i].deny) { @@ -157,8 +158,8 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, } if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%s\"", - value[1].data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%V\"", + &value[1]); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c index 99aa35d88..c78d4e616 100644 --- a/src/http/modules/ngx_http_autoindex_handler.c +++ b/src/http/modules/ngx_http_autoindex_handler.c @@ -24,6 +24,7 @@ typedef struct { typedef struct { ngx_str_t name; + ngx_uint_t escape; ngx_uint_t dir; time_t mtime; off_t size; @@ -269,10 +270,13 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } entry->name.len = len; + entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len, + NGX_ESCAPE_HTML); - if (!(entry->name.data = ngx_palloc(pool, len + 1))) { + if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) { return ngx_http_autoindex_error(r, &dir, dname.data); } + ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1); entry->dir = ngx_de_is_dir(&dir); @@ -298,7 +302,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) for (i = 0; i < entries.nelts; i++) { len += sizeof("<a href=\"") - 1 + 1 /* 1 is for "/" */ - + entry[i].name.len + + entry[i].name.len + entry[i].escape + sizeof("\">") - 1 + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("</a>") - 1 @@ -329,7 +333,17 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) for (i = 0; i < entries.nelts; i++) { b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1); - b->last = ngx_cpymem(b->last, entry[i].name.data, entry[i].name.len); + + if (entry[i].escape) { + ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len, + NGX_ESCAPE_HTML); + + b->last += entry[i].name.len + entry[i].escape; + + } else { + b->last = ngx_cpymem(b->last, entry[i].name.data, + entry[i].name.len); + } if (entry[i].dir) { *b->last++ = '/'; @@ -375,7 +389,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } else { length = entry[i].size; - if (length > 1024 * 1024 * 1024) { + if (length > 1024 * 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024 * 1024)); if ((length % (1024 * 1024 * 1024)) > (1024 * 1024 * 1024 / 2 - 1)) @@ -384,7 +398,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r) } scale = 'G'; - } else if (length > 1024 * 1024) { + } else if (length > 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024)); if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) { size++; diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index f2e85e530..cf9d3d2be 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -125,7 +125,7 @@ ngx_module_t ngx_http_charset_filter_module = { ngx_http_charset_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_charset_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -287,8 +287,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, if (src == dst) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"charset_map\" between the same charsets " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } @@ -299,8 +298,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate \"charset_map\" between " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } } @@ -357,14 +355,14 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) src = ngx_hextoi(value[0].data, value[0].len); if (src == NGX_ERROR || src > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[0].data); + "invalid value \"%V\"", &value[0]); return NGX_CONF_ERROR; } dst = ngx_hextoi(value[1].data, value[1].len); if (dst == NGX_ERROR || dst > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[1].data); + "invalid value \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -525,8 +523,8 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf) ngx_log_error(NGX_LOG_EMERG, cf->log, 0, " no \"charset_map\" between the charsets " - "\"%s\" and \"%s\"", - charset[i].name.data, charset[n].name.data); + "\"%V\" and \"%V\"", + &charset[i].name, &charset[n].name); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c index 7881248cc..929a7ed2c 100644 --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -32,7 +32,7 @@ ngx_module_t ngx_http_chunked_filter_module = { NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_chunked_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -84,7 +84,11 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, size += ngx_buf_size(cl->buf); if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) { - ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + + if (!(tl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + tl->buf = cl->buf; *ll = tl; ll = &tl->next; @@ -102,30 +106,22 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, return NGX_ERROR; } - if (!(chunk = ngx_palloc(r->pool, 11))) { + if (!(chunk = ngx_palloc(r->pool, sizeof("00000000" CRLF) - 1))) { return NGX_ERROR; } b->temporary = 1; b->pos = chunk; - b->last = ngx_sprintf(chunk, "%uxS" CRLF, size); - - out.buf = b; -#if 0 - 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(b, ngx_calloc_buf(r->pool), NGX_ERROR); - b->temporary = 1; - b->pos = chunk; - b->last = chunk + len; + b->last = ngx_sprintf(chunk, "%xz" CRLF, size); out.buf = b; -#endif } if (cl->buf->last_buf) { - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->last_buf = 1; b->pos = (u_char *) CRLF "0" CRLF CRLF; @@ -147,7 +143,10 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r, return ngx_http_next_body_filter(r, out.next); } - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->pos = (u_char *) CRLF; b->last = b->pos + 2; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index bb3a1f0c6..f8980af52 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -80,7 +80,7 @@ static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, 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); -ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); +static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, uintptr_t data); @@ -507,7 +507,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, b->pos = gzheader; b->last = b->pos + 10; - ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; ctx->out = cl; ctx->last_out = &cl->next; @@ -534,7 +538,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, && !ctx->redo) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in: " PTR_FMT, ctx->in); + "gzip in: %p", ctx->in); if (ctx->in == NULL) { break; @@ -547,7 +551,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, 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_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", + "gzip in_buf:%p ni:%p ai:%ud", ctx->in_buf, ctx->zstream.next_in, ctx->zstream.avail_in); @@ -608,10 +612,10 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } 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->redo); + "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", + ctx->zstream.next_in, ctx->zstream.next_out, + ctx->zstream.avail_in, ctx->zstream.avail_out, + ctx->flush, ctx->redo); rc = deflate(&ctx->zstream, ctx->flush); @@ -622,13 +626,13 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d", + "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", ctx->zstream.next_in, ctx->zstream.next_out, ctx->zstream.avail_in, ctx->zstream.avail_out, rc); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, + "gzip in_buf:%p pos:%p", ctx->in_buf, ctx->in_buf->pos); @@ -646,8 +650,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, /* 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)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -663,8 +670,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -686,8 +696,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -703,8 +716,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, b->last_buf = 1; - ngx_alloc_link_and_set_buf(cl, b, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; trailer = (struct gztrailer *) b->pos; @@ -735,8 +751,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -782,10 +801,12 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) ngx_uint_t alloc; alloc = items * size; + if (alloc % 512 != 0) { /* - * the zlib deflate_state allocation, it takes about 6K, we allocate 8K + * The zlib deflate_state allocation, it takes about 6K, + * we allocate 8K. Other allocations are divisible by 512. */ alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); @@ -797,14 +818,14 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) ctx->allocated -= alloc; ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT, + "gzip alloc: n:%ud s:%ud a:%ud p:%p", items, size, alloc, p); return p; } ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, - "gzip filter failed to use preallocated memory: %d of %d", + "gzip filter failed to use preallocated memory: %ud of %ud", items * size, ctx->allocated); p = ngx_palloc(ctx->request->pool, items * size); @@ -819,7 +840,7 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address) ngx_http_gzip_ctx_t *ctx = opaque; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip free: %X", address); + "gzip free: %p", address); #endif } @@ -837,8 +858,6 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, return buf + 1; } - /* we prefer do not use the FPU */ - zint = (ngx_uint_t) (ctx->zin / ctx->zout); zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); @@ -855,16 +874,10 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, } return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, - "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT, - zint, zfrac); -#endif } -ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) +static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) { deflateEnd(&ctx->zstream); diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c index faf81920a..e86f6ae63 100644 --- a/src/http/modules/ngx_http_headers_filter.c +++ b/src/http/modules/ngx_http_headers_filter.c @@ -138,12 +138,6 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r) conf->expires) - cc->value.data; -#if 0 - cc->value.len = ngx_snprintf((char *) cc->value.data, - sizeof("max-age=") + TIME_T_LEN, - "max-age=" TIME_T_FMT, - conf->expires); -#endif } } } diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index 60b6c0185..013f62b46 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -143,7 +143,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) &r->uri, &crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache get: " PTR_FMT, ctx->cache); + "http index cache get: %p", ctx->cache); if (ctx->cache && !ctx->cache->expired) { @@ -251,7 +251,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) err = ngx_errno; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); if (err == NGX_ENOTDIR) { return ngx_http_index_error(r, ctx, err); @@ -275,7 +275,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) } ngx_log_error(NGX_LOG_ERR, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -331,7 +331,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) ctx->redirect.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache alloc: " PTR_FMT, ctx->cache); + "http index cache alloc: %p", ctx->cache); if (ctx->cache) { ctx->cache->fd = NGX_INVALID_FILE; @@ -373,7 +373,7 @@ static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, } ngx_log_error(NGX_LOG_CRIT, r->connection->log, err, - ngx_file_info_n " %s failed", ctx->path.data); + ngx_file_info_n " \"%s\" failed", ctx->path.data); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -502,17 +502,17 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "first index \"%s\" in \"%s\" directive " + "first index \"%V\" in \"%V\" directive " "must not be absolute", - value[1].data, cmd->name.data); + &value[1], &cmd->name); return NGX_CONF_ERROR; } for (i = 1; i < cf->args->nelts; i++) { if (value[i].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "index \"%s\" in \"%s\" directive is invalid", - value[1].data, cmd->name.data); + "index \"%V\" in \"%V\" directive is invalid", + &value[1], &cmd->name); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c index 04d1fde6b..24ea58d90 100644 --- a/src/http/modules/ngx_http_not_modified_filter.c +++ b/src/http/modules/ngx_http_not_modified_filter.c @@ -33,7 +33,7 @@ ngx_module_t ngx_http_not_modified_filter_module = { NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_not_modified_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c index 082fd3c4a..f96456cef 100644 --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -107,11 +107,13 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter; static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) { - ngx_int_t rc; - ngx_uint_t boundary, suffix, i; u_char *p; size_t len; off_t start, end; + ngx_int_t rc; + uint32_t boundary; + ngx_uint_t suffix, i; + ngx_table_elt_t *content_range; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -141,8 +143,11 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) return ngx_http_next_header_filter(r); } - ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t), - NGX_ERROR); + if (ngx_array_init(&r->headers_out.ranges, r->pool, 5, + sizeof(ngx_http_range_t)) == NGX_ERROR) + { + return NGX_ERROR; + } rc = 0; range = NULL; @@ -180,8 +185,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) while (*p == ' ') { p++; } if (*p == ',' || *p == '\0') { - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), - NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; range->end = r->headers_out.content_length_n; @@ -223,7 +230,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) break; } - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; if (end >= r->headers_out.content_length_n) { @@ -249,29 +259,26 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) r->headers_out.status = rc; r->headers_out.ranges.nelts = 0; - r->headers_out.content_range = ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; } - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; + r->headers_out.content_range = content_range; - r->headers_out.content_range->value.data = - ngx_palloc(r->pool, 8 + 20 + 1); - if (r->headers_out.content_range->value.data == NULL) { + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; + + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN); + + if (content_range->value.data == NULL) { return NGX_ERROR; } - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes */%O", r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; -#if 0 - ngx_snprintf((char *) r->headers_out.content_range->value.data, - 8 + 20 + 1, "bytes */" OFF_T_FMT, - r->headers_out.content_length_n); -#endif + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes */%O", + r->headers_out.content_length_n) + - content_range->value.data; r->headers_out.content_length_n = -1; if (r->headers_out.content_length) { @@ -280,177 +287,135 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) } return rc; + } - } else { - r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; + r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; - if (r->headers_out.ranges.nelts == 1) { + if (r->headers_out.ranges.nelts == 1) { - r->headers_out.content_range = - ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { - return NGX_ERROR; - } + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; + r->headers_out.content_range = content_range; - ngx_test_null(r->headers_out.content_range->value.data, - ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1), - NGX_ERROR); + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; - /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); + if (content_range->value.data == NULL) { + return NGX_ERROR; + } - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes %O-%O/%O", - range->start, range->end - 1, - r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; + /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ -#if 0 - ngx_snprintf((char *) - r->headers_out.content_range->value.data, - 6 + 20 + 1 + 20 + 1 + 20 + 1, - "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT, - range->start, range->end - 1, - r->headers_out.content_length_n); -#endif + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes %O-%O/%O", + range->start, range->end - 1, + r->headers_out.content_length_n) + - content_range->value.data; - r->headers_out.content_length_n = range->end - range->start; + r->headers_out.content_length_n = range->end - range->start; - } else { + return ngx_http_next_header_filter(r); + } -#if 0 - /* TODO: what if no content_type ?? */ - if (!(r->headers_out.content_type = - ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) - { - return NGX_ERROR; - } -#endif + /* TODO: what if no content_type ?? */ - ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, - sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); + ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, + sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); - len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len - + 2 + 21 + 1; - if (r->headers_out.charset.len) { - len += 10 + r->headers_out.charset.len; - } + len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1 + + r->headers_out.content_type->value.len + + sizeof(CRLF "Content-Range: bytes ") - 1; - ngx_test_null(ctx->boundary_header.data, ngx_palloc(r->pool, len), - NGX_ERROR); + if (r->headers_out.charset.len) { + len += sizeof("; charset=") - 1 + r->headers_out.charset.len; + } - boundary = ngx_next_temp_number(0); + if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) { + return NGX_ERROR; + } - /* - * The boundary header of the range: - * CRLF - * "--0123456789" CRLF - * "Content-Type: image/jpeg" CRLF - * "Content-Range: bytes " - */ + boundary = ngx_next_temp_number(0); - if (r->headers_out.charset.len) { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data) - - ctx->boundary_header.data; -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data); -#endif - - r->headers_out.charset.len = 0; - - } else { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data) - - ctx->boundary_header.data; - -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data); - -#endif - } + /* + * The boundary header of the range: + * CRLF + * "--0123456789" CRLF + * "Content-Type: image/jpeg" CRLF + * "Content-Range: bytes " + */ - ngx_test_null(r->headers_out.content_type->value.data, - ngx_palloc(r->pool, 31 + 10 + 1), - NGX_ERROR); - - /* "Content-Type: multipart/byteranges; boundary=0123456789" */ - - r->headers_out.content_type->value.len = - ngx_sprintf(r->headers_out.content_type->value.data, - "multipart/byteranges; boundary=%010ui", - boundary) - - r->headers_out.content_type->value.data; -#if 0 - ngx_snprintf((char *) - r->headers_out.content_type->value.data, - 31 + 10 + 1, - "multipart/byteranges; boundary=%010" - NGX_UINT_T_FMT, - boundary); -#endif - - /* the size of the last boundary CRLF "--0123456789--" CRLF */ - len = 4 + 10 + 4; - - range = r->headers_out.ranges.elts; - for (i = 0; i < r->headers_out.ranges.nelts; i++) { - ngx_test_null(range[i].content_range.data, - ngx_palloc(r->pool, 20 + 1 + 20 + 1 + 20 + 5), - NGX_ERROR); - - /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ - - range[i].content_range.len = - ngx_sprintf(range[i].content_range.data, - "%O-%O/%O" CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n) - - range[i].content_range.data; -#if 0 - ngx_snprintf((char *) range[i].content_range.data, - 20 + 1 + 20 + 1 + 20 + 5, - OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n); -#endif - - len += ctx->boundary_header.len + range[i].content_range.len - + (size_t) (range[i].end - range[i].start); - } + if (r->headers_out.charset.len) { + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V; charset=%V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value, + &r->headers_out.charset) + - ctx->boundary_header.data; - r->headers_out.content_length_n = len; - r->headers_out.content_length = NULL; + r->headers_out.charset.len = 0; + + } else { + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value) + - ctx->boundary_header.data; + } + + r->headers_out.content_type->value.data = + ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; " + "boundary=0123456789") - 1); + + if (r->headers_out.content_type->value.data == NULL) { + return NGX_ERROR; + } + + /* "Content-Type: multipart/byteranges; boundary=0123456789" */ + + r->headers_out.content_type->value.len = + ngx_sprintf(r->headers_out.content_type->value.data, + "multipart/byteranges; boundary=%010ud", + boundary) + - r->headers_out.content_type->value.data; + + /* the size of the last boundary CRLF "--0123456789--" CRLF */ + len = sizeof(CRLF "--0123456789--" CRLF) - 1; + + range = r->headers_out.ranges.elts; + for (i = 0; i < r->headers_out.ranges.nelts; i++) { + + /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ + + range[i].content_range.data = + ngx_palloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4); + + if (range[i].content_range.data == NULL) { + return NGX_ERROR; } + + range[i].content_range.len = ngx_sprintf(range[i].content_range.data, + "%O-%O/%O" CRLF CRLF, + range[i].start, range[i].end - 1, + r->headers_out.content_length_n) + - range[i].content_range.data; + + len += ctx->boundary_header.len + range[i].content_range.len + + (size_t) (range[i].end - range[i].start); } + r->headers_out.content_length_n = len; + r->headers_out.content_length = NULL; + return ngx_http_next_header_filter(r); } @@ -496,33 +461,54 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, * "Content-Range: bytes " */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return 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); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + hcl->buf = b; + /* "SSSS-EEEE/TTTT" CRLF CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return 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); + if (!(rcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + rcl->buf = b; + /* the range data */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return 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_buf(dcl, b, r->pool, NGX_ERROR); + if (!(dcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + dcl->buf = b; *ll = hcl; hcl->next = rcl; @@ -532,15 +518,29 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, /* the last boundary CRLF "--0123456789--" CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->temporary = 1; b->last_buf = 1; - ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); + + b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1); + if (b->pos == NULL) { + return 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_buf(hcl, b, r->pool, NGX_ERROR); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + hcl->buf = b; + hcl->next = NULL; + *ll = hcl; return ngx_http_next_body_filter(r, out); diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c index aa3a65648..0973ef087 100644 --- a/src/http/modules/ngx_http_rewrite_handler.c +++ b/src/http/modules/ngx_http_rewrite_handler.c @@ -146,8 +146,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) if (rc == NGX_DECLINED) { if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" does not match \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" does not match \"%V\"", + &rule[i].re_name, &r->uri); } continue; @@ -156,15 +156,15 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) if (rc < 0) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_regex_exec_n - " failed: %d on \"%s\" using \"%s\"", - rc, r->uri.data, rule[i].re_name.data); + " failed: %d on \"%V\" using \"%V\"", + rc, &r->uri, &rule[i].re_name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" matches \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" matches \"%V\"", + &rule[i].re_name, &r->uri); } if (rule[i].status) { @@ -177,7 +177,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) uri.len += matches[2 * n + 1] - matches[2 * n]; } - if (!(uri.data = ngx_palloc(r->pool, uri.len + 1))) { + if (!(uri.data = ngx_palloc(r->pool, uri.len))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -203,11 +203,9 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r) } } - *p = '\0'; - if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "rewritten uri: \"%s\"", uri.data); + "rewritten uri: \"%V\"", &uri); } r->uri = uri; @@ -353,7 +351,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd, } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } @@ -427,7 +425,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd, } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index c4ffde3b2..12cf5b39d 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -197,7 +197,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) &name, &file_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache get: " PTR_FMT, file); + "http open file cache get: %p", file); if (file && !file->expired) { r->cache = file; @@ -216,7 +216,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) &name, &redirect_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache get: " PTR_FMT, redirect); + "http redirect cache get: %p", redirect); if (redirect && !redirect->expired) { @@ -247,7 +247,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) /* open file */ -#if (WIN9X) +#if (NGX_WIN9X) /* TODO: redirect cache */ @@ -276,7 +276,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) } if (ngx_is_dir(&fi)) { - ngx_log_debug(log, "HTTP DIR: '%s'" _ name.data); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, + "HTTP DIR: \"%s\"", name.data); if (!(r->headers_out.location = ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) @@ -384,7 +385,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) location.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache alloc: " PTR_FMT, redirect); + "http redirect cache alloc: %p", redirect); if (redirect) { redirect->fd = NGX_INVALID_FILE; @@ -403,11 +404,11 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) return NGX_HTTP_MOVED_PERMANENTLY; } -#if !(WIN32) /* the not regular files are probably Unix specific */ +#if !(NGX_WIN32) /* the not regular files are probably Unix specific */ if (!ngx_is_file(&fi)) { ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, - "%s is not a regular file", name.data); + "\"%s\" is not a regular file", name.data); if (ngx_close_file(fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, @@ -459,7 +460,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) #endif ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache alloc: " PTR_FMT, file); + "http open file cache alloc: %p", file); if (file) { file->fd = fd; diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_handler.c index 357affff4..ce49ae426 100644 --- a/src/http/modules/ngx_http_status_handler.c +++ b/src/http/modules/ngx_http_status_handler.c @@ -171,10 +171,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx) return NGX_ERROR; } - b->last += ngx_snprintf((char *) b->last, - /* STUB: should be NGX_PID_T_LEN */ - NGX_INT64_LEN + NGX_INT32_LEN, - PID_T_FMT " %4u", ngx_pid, i); + b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i); switch (r->http_state) { case NGX_HTTP_INITING_REQUEST_STATE: @@ -250,10 +247,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx) return NGX_ERROR; } - b->last += ngx_snprintf((char *) b->last, - /* STUB: should be NGX_PID_T_LEN */ - NGX_INT64_LEN + NGX_INT32_LEN, - PID_T_FMT " %4u", ngx_pid, i); + b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i); *(b->last++) = ' '; *(b->last++) = 's'; diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c index bafdea884..2385ceed2 100644 --- a/src/http/modules/ngx_http_userid_filter.c +++ b/src/http/modules/ngx_http_userid_filter.c @@ -27,15 +27,13 @@ typedef struct { ngx_str_t domain; ngx_str_t path; time_t expires; - - ngx_int_t p3p; - ngx_str_t p3p_string; + ngx_str_t p3p; } ngx_http_userid_conf_t; typedef struct { - uint32_t uid_got[4]; - uint32_t uid_set[4]; + uint32_t uid_got[4]; + uint32_t uid_set[4]; } ngx_http_userid_ctx_t; @@ -56,8 +54,10 @@ static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf); static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child); -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); static uint32_t sequencer_v1 = 1; @@ -79,8 +79,11 @@ static ngx_conf_enum_t ngx_http_userid_state[] = { }; -static ngx_conf_post_handler_pt ngx_conf_check_domain_p = - ngx_conf_check_domain; +static ngx_conf_post_handler_pt ngx_http_userid_domain_p = + ngx_http_userid_domain; + +static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; +static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p; static ngx_command_t ngx_http_userid_commands[] = { @@ -111,14 +114,14 @@ static ngx_command_t ngx_http_userid_commands[] = { ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, domain), - &ngx_conf_check_domain_p }, + &ngx_http_userid_domain_p }, { ngx_string("userid_path"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, path), - NULL }, + &ngx_http_userid_path_p }, { ngx_string("userid_expires"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, @@ -127,6 +130,13 @@ static ngx_command_t ngx_http_userid_commands[] = { 0, NULL }, + { ngx_string("userid_p3p"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_userid_conf_t, p3p), + &ngx_http_userid_p3p_p }, + ngx_null_command }; @@ -210,40 +220,44 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, for (i = 0; i < r->headers_in.cookies.nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "cookie: \"%s\"", cookies[i]->value.data); + "cookie: \"%V\"", &cookies[i]->value); + if (conf->name.len >= cookies[i]->value.len) { + continue; + } + + start = cookies[i]->value.data; end = cookies[i]->value.data + cookies[i]->value.len; - for (start = cookies[i]->value.data; start < end; /* void */) { + while (start < end) { - if (conf->name.len >= cookies[i]->value.len - || ngx_strncmp(start, conf->name.data, conf->name.len) != 0) - { - start += conf->name.len; - while (start < end && *start++ != ';') { /* void */ } + if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) { - for (/* void */; start < end && *start == ' '; start++) { /**/ } + while (start < end && *start++ != ';') { /* void */ } + while (start < end && *start == ' ') { start++; } continue; } - for (start += conf->name.len; start < end && *start == ' '; start++) - { - /* void */ - } + start += conf->name.len; - if (*start != '=') { + while (start < end && *start == ' ') { start++; } + + if (start == end || *start++ != '=') { + /* the invalid "Cookie" header */ break; } - for (start++; start < end && *start == ' '; start++) { /* void */ } + while (start < end && *start == ' ') { start++; } + + last = start; - for (last = start; last < end && *last != ';'; last++) { /**/ } + while (last < end && *last++ != ';') { /* void */ } if (last - start < 22) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent too short userid cookie \"%s\"", - cookies[i]->value.data); + "client sent too short userid cookie \"%V\"", + &cookies[i]->value); break; } @@ -259,13 +273,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent invalid userid cookie \"%s\"", - cookies[i]->value.data); + "client sent invalid userid cookie \"%V\"", + &cookies[i]->value); break; } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid: %08X%08X%08X%08X", + "uid: %08XD%08XD%08XD%08XD", ctx->uid_got[0], ctx->uid_got[1], ctx->uid_got[2], ctx->uid_got[3]); @@ -280,14 +294,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r, static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf) - { u_char *cookie, *p; size_t len; socklen_t slen; struct sockaddr_in addr_in; ngx_str_t src, dst; - ngx_table_elt_t *set_cookie; + ngx_table_elt_t *set_cookie, *p3p; /* TODO: mutex for sequencers */ @@ -333,18 +346,14 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, } } - len = conf->name.len + 1 + ngx_base64_encoded_length(16) + 1; + len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len; if (conf->expires) { len += sizeof(expires) - 1 + 2; } if (conf->domain.len > 1) { - len += sizeof("; domain=") - 1 + conf->domain.len; - } - - if (conf->path.len) { - len += sizeof("; path=") - 1 + conf->path.len; + len += conf->domain.len; } if (!(cookie = ngx_palloc(r->pool, len))) { @@ -371,19 +380,10 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, } if (conf->domain.len > 1) { - p = ngx_cpymem(p, "; domain=", sizeof("; domain=") - 1); p = ngx_cpymem(p, conf->domain.data, conf->domain.len); } - if (conf->path.len) { - p = ngx_cpymem(p, "; path=", sizeof("; path=") - 1); - p = ngx_cpymem(p, conf->path.data, conf->path.len); - } - - *p = '\0'; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid cookie: \"%s\"", cookie); + p = ngx_cpymem(p, conf->path.data, conf->path.len); if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; @@ -394,6 +394,21 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, set_cookie->value.len = p - cookie; set_cookie->value.data = cookie; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "uid cookie: \"%V\"", &set_cookie->value); + + if (conf->p3p.len == 1) { + return NGX_OK; + } + + if (!(p3p = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } + + p3p->key.len = sizeof("P3P") - 1; + p3p->key.data = (u_char *) "P3P"; + p3p->value = conf->p3p; + return NGX_OK; } @@ -425,9 +440,9 @@ static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf, *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_got[0], ctx->uid_got[1], - ctx->uid_got[2], ctx->uid_got[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_got[0], ctx->uid_got[1], + ctx->uid_got[2], ctx->uid_got[3]); } @@ -458,9 +473,9 @@ static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_set[0], ctx->uid_set[1], - ctx->uid_set[2], ctx->uid_set[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_set[0], ctx->uid_set[1], + ctx->uid_set[2], ctx->uid_set[3]); } @@ -510,6 +525,8 @@ static void *ngx_http_userid_create_conf(ngx_conf_t *cf) conf->domain.date = NULL; conf->path.len = 0; conf->path.date = NULL; + conf->p3p.len = 0; + conf->p3p.date = NULL; */ @@ -531,7 +548,8 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, ngx_conf_merge_str_value(conf->name, prev->name, "uid"); ngx_conf_merge_str_value(conf->domain, prev->domain, "."); - ngx_conf_merge_str_value(conf->path, prev->path, "/"); + ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); + ngx_conf_merge_str_value(conf->p3p, prev->p3p, "."); ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); @@ -540,15 +558,49 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, } -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data) +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) { ngx_str_t *domain = data; + u_char *p, *new; + if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { domain->len = 1; domain->data = (u_char *) "."; + + return NGX_CONF_OK; + } + + if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { + return NGX_CONF_ERROR; + } + + p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); + p = ngx_cpymem(p, domain->data, domain->len); + + domain->len += sizeof("; domain=") - 1; + domain->data = new; + + return NGX_CONF_OK; +} + + +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *path = data; + + u_char *p, *new; + + if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) { + return NGX_CONF_ERROR; } + p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); + p = ngx_cpymem(p, path->data, path->len); + + path->len += sizeof("; path=") - 1; + path->data = new; + return NGX_CONF_OK; } @@ -586,3 +638,16 @@ char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_OK; } + + +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *p3p = data; + + if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { + p3p->len = 1; + p3p->data = (u_char *) "."; + } + + return NGX_CONF_OK; +} diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c index 0a2a20025..f0b56f548 100644 --- a/src/http/modules/proxy/ngx_http_proxy_cache.c +++ b/src/http/modules/proxy/ngx_http_proxy_cache.c @@ -173,8 +173,8 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p) ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache status %d \"%s\"", - c->status, c->status_line.data); + "http cache status %ui \"%V\"", + c->status, &c->status_line); /* TODO: ngx_init_table */ c->headers_in.headers = ngx_create_table(r->pool, 20); @@ -219,8 +219,7 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p) } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache header: \"%s: %s\"", - h->key.data, h->value.data); + "http cache header: \"%V: %V\"", &h->key, &h->value); continue; @@ -614,7 +613,7 @@ int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p) ep = p->upstream->event_pipe; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http cache update len: " OFF_T_FMT ":" OFF_T_FMT, + "http cache update len: %O:%O", p->cache->ctx.length, ep->read_length); if (p->cache->ctx.length == -1) { diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 64f7c0794..915d378e6 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -710,26 +710,75 @@ void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) } -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len) { ngx_http_proxy_log_ctx_t *ctx = data; - ngx_http_request_t *r; - ngx_peer_connection_t *peer; + u_char *p; + ngx_int_t escape; + ngx_str_t uri; + ngx_http_request_t *r; + ngx_peer_connection_t *peer; + ngx_http_proxy_upstream_conf_t *uc; r = ctx->proxy->request; + uc = ctx->proxy->lcf->upstream; peer = &ctx->proxy->upstream->peer; - return ngx_snprintf(buf, len, - " while %s, client: %s, URL: %s, upstream: %s%s%s%s%s", - ctx->proxy->action, - r->connection->addr_text.data, - r->unparsed_uri.data, - peer->peers->peers[peer->cur_peer].addr_port_text.data, - ctx->proxy->lcf->upstream->uri.data, - r->uri.data + ctx->proxy->lcf->upstream->location->len, - r->args.len ? "?" : "", - r->args.len ? r->args.data : (u_char *) ""); + p = ngx_snprintf(buf, len, + " while %s, client: %V, URL: %V, upstream: %V%V", + ctx->proxy->action, + &r->connection->addr_text, + &r->unparsed_uri, + &peer->peers->peers[peer->cur_peer].addr_port_text, + &ctx->proxy->lcf->upstream->uri); + len -= p - buf; + buf = p; + + if (r->quoted_uri) { + escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); + } else { + escape = 0; + } + + if (escape) { + if (len >= r->uri.len - uc->location->len + escape) { + + ngx_escape_uri(buf, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + buf += r->uri.len - uc->location->len + escape; + + if (r->args.len == 0) { + return buf; + } + + len -= r->uri.len - uc->location->len + escape; + + return ngx_snprintf(buf, len, "?%V", &r->args); + } + + p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape); + if (p == NULL) { + return buf; + } + + ngx_escape_uri(p, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + uri.len = r->uri.len - uc->location->len + escape; + uri.data = p; + + } else { + uri.len = r->uri.len - uc->location->len; + uri.data = r->uri.data + uc->location->len; + + } + + return ngx_snprintf(buf, len, "%V%s%V", + &uri, r->args.len ? "?" : "", &r->args); } @@ -759,8 +808,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expired); + buf = ngx_sprintf(buf, "%T", p->state->expired); } *buf++ = '/'; @@ -769,8 +817,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->bl_time); + buf = ngx_sprintf(buf, "%T", p->state->bl_time); } *buf++ = '/'; @@ -783,8 +830,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, - p->state->status); + buf = ngx_sprintf(buf, "%ui", p->state->status); } *buf++ = '/'; @@ -803,8 +849,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expires); + buf = ngx_sprintf(buf, "%T", p->state->expires); } *buf++ = ' '; @@ -1166,7 +1211,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]); lcf->peers->peers[i].port = lcf->upstream->port; - len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1; + len = INET_ADDRSTRLEN - 1 + 1 + lcf->upstream->port_text.len; lcf->peers->peers[i].addr_port_text.data = ngx_palloc(cf->pool, len); @@ -1181,12 +1226,12 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[i].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[i].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[i].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); lcf->peers->peers[i].addr_port_text.len = - len + lcf->upstream->port_text.len + 1; + len + lcf->upstream->port_text.len; } } else { @@ -1204,10 +1249,11 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[0].addr = addr; lcf->peers->peers[0].port = lcf->upstream->port; - len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1; + len = lcf->upstream->host.len + 1 + lcf->upstream->port_text.len; + + lcf->peers->peers[0].addr_port_text.len = len; - lcf->peers->peers[0].addr_port_text.data = - ngx_palloc(cf->pool, len + 1); + lcf->peers->peers[0].addr_port_text.data = ngx_palloc(cf->pool, len); if (lcf->peers->peers[0].addr_port_text.data == NULL) { return NGX_CONF_ERROR; } @@ -1219,9 +1265,9 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->peers[0].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[0].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[0].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 76db65282..094ee3bd1 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -245,7 +245,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev); void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev); void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p); -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len); +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len); void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc); void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p); diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 9b3d8847e..0852a426f 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -25,7 +25,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); static void ngx_http_proxy_process_body(ngx_event_t *ev); -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type); +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type); static ngx_str_t http_methods[] = { @@ -137,7 +138,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) if (r->quoted_uri) { escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); } else { escape = 0; } @@ -246,7 +248,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) if (escape) { ngx_escape_uri(b->last, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, NGX_ESCAPE_URI); b->last += r->uri.len - uc->location->len + escape; } else { @@ -409,8 +411,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) *(b->last++) = CR; *(b->last++) = LF; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http proxy header: \"%s: %s\"", - header[i].key.data, header[i].value.data); + "http proxy header: \"%V: %V\"", + &header[i].key, &header[i].value); } /* add "\r\n" at the header end */ @@ -670,7 +672,7 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p) static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) { - int rc; + ngx_int_t rc; ngx_connection_t *c; ngx_http_request_t *r; ngx_output_chain_ctx_t *output; @@ -683,7 +685,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) rc = ngx_event_connect_peer(&p->upstream->peer); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy connect: %d", rc); + "http proxy connect: %i", rc); if (rc == NGX_ERROR) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -705,6 +707,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) c->write->event_handler = ngx_http_proxy_send_request_handler; c->read->event_handler = ngx_http_proxy_process_upstream_status_line; + c->sendfile = r->connection->sendfile; + c->pool = r->pool; c->read->log = c->write->log = c->log = r->connection->log; @@ -1028,8 +1032,8 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev) p->upstream->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, - "http proxy status %d \"%s\"", - p->upstream->status, p->upstream->status_line.data); + "http proxy status %ui \"%V\"", + p->upstream->status, &p->upstream->status_line); /* init or reinit the p->upstream->headers_in.headers table */ @@ -1143,8 +1147,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev) } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http proxy header: \"%s: %s\"", - h->key.data, h->value.data); + "http proxy header: \"%V: %V\"", &h->key, &h->value); continue; @@ -1467,7 +1470,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev) if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, - "http proxy upstream exit: " PTR_FMT, ep->out); + "http proxy upstream exit: %p", ep->out); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); ngx_http_proxy_finalize_request(p, 0); return; @@ -1484,12 +1487,13 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev) } -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type) +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type) { - int status; + ngx_uint_t status; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy next upstream: %d", ft_type); + "http proxy next upstream: %ui", ft_type); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); |
