diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-10-25 15:29:23 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-10-25 15:29:23 +0000 |
commit | 723e6cc248470b95f62e338cd5e1a6514975f9cc (patch) | |
tree | dd9fb2b16d384f241c2303d3cbb6e25aeeb89ab0 /src/http/modules/proxy | |
parent | 4925ed843a96d9b2dbb41ef961cc37e9fa03539a (diff) | |
download | nginx-723e6cc248470b95f62e338cd5e1a6514975f9cc.tar.gz nginx-723e6cc248470b95f62e338cd5e1a6514975f9cc.zip |
nginx-0.1.3-RELEASE importrelease-0.1.3
*) Feature: the ngx_http_autoindex_module and the autoindex directive.
*) Feature: the proxy_set_x_url directive.
*) Bugfix: proxy module may get caught in an endless loop when sendfile
is not used.
Diffstat (limited to 'src/http/modules/proxy')
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.c | 13 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_handler.h | 1 | ||||
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_upstream.c | 86 |
3 files changed, 87 insertions, 13 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index 5d61167e2..64f7c0794 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -98,6 +98,13 @@ static ngx_command_t ngx_http_proxy_commands[] = { offsetof(ngx_http_proxy_loc_conf_t, preserve_host), NULL }, + { ngx_string("proxy_set_x_url"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_proxy_loc_conf_t, set_x_url), + NULL }, + { ngx_string("proxy_set_x_real_ip"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_flag_slot, @@ -894,6 +901,7 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) conf->send_lowat = NGX_CONF_UNSET_SIZE; conf->preserve_host = NGX_CONF_UNSET; + conf->set_x_url = NGX_CONF_UNSET; conf->set_x_real_ip = NGX_CONF_UNSET; conf->add_x_forwarded_for = NGX_CONF_UNSET; @@ -938,6 +946,7 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0); + ngx_conf_merge_value(conf->set_x_url, prev->set_x_url, 0); ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0); ngx_conf_merge_value(conf->add_x_forwarded_for, prev->add_x_forwarded_for, 0); @@ -1147,6 +1156,10 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, lcf->peers->number = i; + /* STUB */ + lcf->peers->max_fails = 1; + lcf->peers->fail_timeout = 60; + for (i = 0; h->h_addr_list[i] != NULL; i++) { lcf->peers->peers[i].host.data = host; lcf->peers->peers[i].host.len = lcf->upstream->host.len; diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 3e721bae1..76db65282 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -75,6 +75,7 @@ typedef struct { ngx_flag_t cyclic_temp_file; ngx_flag_t cache; ngx_flag_t preserve_host; + ngx_flag_t set_x_url; ngx_flag_t set_x_real_ip; ngx_flag_t add_x_forwarded_for; ngx_flag_t pass_server; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 88479daf5..9b3d8847e 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -43,6 +43,7 @@ static char *upstream_header_errors[] = { static char http_version[] = " HTTP/1.0" CRLF; static char host_header[] = "Host: "; +static char x_url_header[] = "X-URL: http"; static char x_real_ip_header[] = "X-Real-IP: "; static char x_forwarded_for_header[] = "X-Forwarded-For: "; static char connection_close_header[] = "Connection: close" CRLF; @@ -142,18 +143,36 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) } len += uc->uri.len - + r->uri.len - uc->location->len + escape - + 1 + r->args.len /* 1 is for "?" */ - + sizeof(http_version) - 1 - + sizeof(connection_close_header) - 1 - + 2; /* 2 is for "\r\n" at the header end */ + + r->uri.len - uc->location->len + escape + + 1 + r->args.len /* 1 is for "?" */ + + sizeof(http_version) - 1 + + sizeof(connection_close_header) - 1 + + 2; /* 2 is for "\r\n" at the header end */ + + + if (p->lcf->set_x_url) { + len += sizeof(x_url_header) - 1 + + 4 /* 4 is for "s://" */ + + r->port_text->len + + r->unparsed_uri.len + + 2; /* 2 is for "\r\n" at the header end */ + + if (r->headers_in.host) { + len += r->headers_in.host_name_len; + + } else { + len += r->server_name.len; + } + + } + if (p->lcf->preserve_host && r->headers_in.host) { len += sizeof(host_header) - 1 - + r->headers_in.host_name_len - + 1 /* 1 is for ":" */ - + uc->port_text.len - + 2; /* 2 is for "\r\n" */ + + r->headers_in.host_name_len + + 1 /* 1 is for ":" */ + + uc->port_text.len + + 2; /* 2 is for "\r\n" */ } else { /* 2 is for "\r\n" */ len += sizeof(host_header) - 1 + uc->host_header.len + 2; } @@ -167,10 +186,10 @@ 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) { len += sizeof(x_forwarded_for_header) - 1 - + r->headers_in.x_forwarded_for->value.len - + 2 /* 2 is ofr ", " */ - + INET_ADDRSTRLEN - 1 - + 2; /* 2 is for "\r\n" */ + + r->headers_in.x_forwarded_for->value.len + + 2 /* 2 is ofr ", " */ + + INET_ADDRSTRLEN - 1 + + 2; /* 2 is for "\r\n" */ } else { len += sizeof(x_forwarded_for_header) - 1 + INET_ADDRSTRLEN - 1 + 2; /* 2 is for "\r\n" */ @@ -271,6 +290,39 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) *(b->last++) = CR; *(b->last++) = LF; + /* the "X-URL" header */ + + if (p->lcf->set_x_url) { + + b->last = ngx_cpymem(b->last, x_url_header, + sizeof(x_url_header) - 1); + +#if (NGX_OPENSSL) + + if (r->connection->ssl) { + *(b->last++) = 's'; + } + +#endif + + *(b->last++) = ':'; *(b->last++) = '/'; *(b->last++) = '/'; + + if (r->headers_in.host) { + b->last = ngx_cpymem(b->last, r->headers_in.host->value.data, + r->headers_in.host_name_len); + } else { + b->last = ngx_cpymem(b->last, r->server_name.data, + r->server_name.len); + } + + b->last = ngx_cpymem(b->last, r->port_text->data, r->port_text->len); + b->last = ngx_cpymem(b->last, r->unparsed_uri.data, + r->unparsed_uri.len); + + *(b->last++) = CR; *(b->last++) = LF; + } + + /* the "X-Real-IP" header */ if (p->lcf->set_x_real_ip) { @@ -339,6 +391,14 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p) continue; } + if (&header[i] == r->headers_in.x_real_ip && p->lcf->set_x_real_ip) { + continue; + } + + if (&header[i] == r->headers_in.x_url && p->lcf->set_x_url) { + continue; + } + b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); *(b->last++) = ':'; *(b->last++) = ' '; |