diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-11-11 14:07:14 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-11-11 14:07:14 +0000 |
| commit | 1b73583ba2c0e4b72d951218827e0c621427d389 (patch) | |
| tree | 9e4d204e2cce91560d5cb8908b8a1a9f2c1d92ee /src/http/modules/proxy | |
| parent | d6f24959428caed68a509a19ca4fd866d978a69c (diff) | |
| download | nginx-release-0.1.5.tar.gz nginx-release-0.1.5.tar.bz2 | |
nginx-0.1.5-RELEASE importrelease-0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
Diffstat (limited to 'src/http/modules/proxy')
| -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 |
4 files changed, 102 insertions, 53 deletions
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); |
