nginx-0.0.2-2004-03-14-23:46:25 import
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index d5ecd41..bec9d65 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -98,7 +98,6 @@
int ngx_http_index_handler(ngx_http_request_t *r)
{
char *name;
- uint32_t crc;
size_t len;
ngx_fd_t fd;
ngx_int_t rc;
@@ -108,6 +107,9 @@
ngx_http_index_ctx_t *ctx;
ngx_http_core_loc_conf_t *clcf;
ngx_http_index_loc_conf_t *ilcf;
+#if (NGX_HTTP_CACHE)
+ uint32_t crc;
+#endif
if (r->uri.data[r->uri.len - 1] != '/') {
return NGX_DECLINED;
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 6925a03..7876d2a 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -61,7 +61,6 @@
static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
{
char *last;
- uint32_t file_crc, redirect_crc;
ngx_fd_t fd;
ngx_int_t rc;
ngx_uint_t level;
@@ -71,11 +70,14 @@
ngx_hunk_t *h;
ngx_chain_t out;
ngx_file_info_t fi;
- ngx_http_cache_t *file, *redirect;
ngx_http_cleanup_t *file_cleanup, *redirect_cleanup;
ngx_http_log_ctx_t *ctx;
ngx_http_core_loc_conf_t *clcf;
ngx_http_static_loc_conf_t *slcf;
+#if (NGX_HTTP_CACHE)
+ uint32_t file_crc, redirect_crc;
+ ngx_http_cache_t *file, *redirect;
+#endif
if (r->uri.data[r->uri.len - 1] == '/') {
return NGX_DECLINED;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 669a970..e382f05 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -81,6 +81,13 @@
offsetof(ngx_http_proxy_loc_conf_t, send_timeout),
NULL },
+ { ngx_string("proxy_preserve_host"),
+ 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, preserve_host),
+ 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,
@@ -774,6 +781,7 @@
conf->connect_timeout = NGX_CONF_UNSET;
conf->send_timeout = NGX_CONF_UNSET;
+ conf->preserve_host = NGX_CONF_UNSET;
conf->set_x_real_ip = NGX_CONF_UNSET;
conf->add_x_forwarded_for = NGX_CONF_UNSET;
@@ -816,6 +824,7 @@
prev->connect_timeout, 60000);
ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 30000);
+ ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 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);
@@ -1057,6 +1066,7 @@
}
if (u->port_text.data == NULL) {
+ u->default_port = 1;
u->port = htons(80);
u->port_text.len = 2;
u->port_text.data = "80";
@@ -1087,6 +1097,7 @@
u->uri.len = 1;
if (u->port_text.data == NULL) {
+ u->default_port = 1;
u->port = htons(80);
u->port_text.len = 2;
u->port_text.data = "80";
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 44fb662..dd9cd15 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -41,6 +41,7 @@
ngx_str_t port_text;
ngx_str_t *location;
int port;
+ unsigned default_port:1;
} ngx_http_proxy_upstream_conf_t;
@@ -60,6 +61,7 @@
ngx_flag_t cache;
+ ngx_flag_t preserve_host;
ngx_flag_t set_x_real_ip;
ngx_flag_t add_x_forwarded_for;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 67dabe9..dc55050 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -57,6 +57,7 @@
p->upstream = u;
+ u->peer.log_error = NGX_ERROR_ERR;
u->peer.peers = p->lcf->peers;
u->peer.tries = p->lcf->peers->number;
@@ -113,21 +114,29 @@
+ r->uri.len - uc->location->len
+ 1 + r->args.len /* 1 is for "?" */
+ sizeof(http_version) - 1
- + sizeof(host_header) - 1 + uc->host_header.len + 2
- /* 2 is for "\r\n" */
+ sizeof(connection_close_header) - 1
+ 2; /* 2 is for "\r\n" at the header end */
- if (p->lcf->set_x_real_ip) {
- /* 2 is for "\r\n" */
+
+ if (p->lcf->preserve_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" */
+ } else { /* 2 is for "\r\n" */
+ len += sizeof(host_header) - 1 + uc->host_header.len + 2;
+ }
+
+
+ if (p->lcf->set_x_real_ip) { /* 2 is for "\r\n" */
len += sizeof(x_real_ip_header) - 1 + INET_ADDRSTRLEN - 1 + 2;
}
if (p->lcf->add_x_forwarded_for) {
if (r->headers_in.x_forwarded_for) {
- len += r->headers_in.x_forwarded_for->key.len
- + 2 /* 2 is ofr ": " */
+ len += sizeof(x_forwarded_for_header) - 1
+ r->headers_in.x_forwarded_for->value.len
+ 2 /* 2 is ofr ", " */
+ INET_ADDRSTRLEN - 1
@@ -179,19 +188,33 @@
h->last = ngx_cpymem(h->last, http_version, sizeof(http_version) - 1);
- /* the "Host" header */
-
- h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
- h->last = ngx_cpymem(h->last, uc->host_header.data, uc->host_header.len);
- *(h->last++) = CR; *(h->last++) = LF;
-
-
/* the "Connection: close" header */
h->last = ngx_cpymem(h->last, connection_close_header,
sizeof(connection_close_header) - 1);
+ /* the "Host" header */
+
+ h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
+
+ if (p->lcf->preserve_host) {
+ h->last = ngx_cpymem(h->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,
+ uc->port_text.len);
+ }
+
+ } else {
+ h->last = ngx_cpymem(h->last, uc->host_header.data,
+ uc->host_header.len);
+ }
+ *(h->last++) = CR; *(h->last++) = LF;
+
+
/* the "X-Real-IP" header */
if (p->lcf->set_x_real_ip) {
@@ -207,11 +230,8 @@
if (p->lcf->add_x_forwarded_for) {
if (r->headers_in.x_forwarded_for) {
- h->last = ngx_cpymem(h->last,
- r->headers_in.x_forwarded_for->key.data,
- r->headers_in.x_forwarded_for->key.len);
-
- *(h->last++) = ':'; *(h->last++) = ' ';
+ h->last = ngx_cpymem(h->last, x_forwarded_for_header,
+ sizeof(x_forwarded_for_header) - 1);
h->last = ngx_cpymem(h->last,
r->headers_in.x_forwarded_for->value.data,
@@ -416,7 +436,10 @@
void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
{
- int rc, ft_type;
+ ngx_int_t rc;
+#if (NGX_HTTP_CACHE)
+ ngx_int_t ft_type;
+#endif
if (p->busy_lock.time == 0) {
p->busy_lock.event = p->request->connection->read;
@@ -436,6 +459,8 @@
ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+#if (NGX_HTTP_CACHE)
+
if (rc == NGX_DONE) {
ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
@@ -444,8 +469,6 @@
ft_type = NGX_HTTP_PROXY_FT_MAX_WAITING;
}
-#if (NGX_HTTP_CACHE)
-
if (p->stale && (p->lcf->use_stale & ft_type)) {
ngx_http_proxy_finalize_request(p,
ngx_http_proxy_send_cached_response(p));
@@ -1067,13 +1090,13 @@
ep->pool = r->pool;
ep->log = r->connection->log;
+ ep->cachable = p->cachable;
+
if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
ngx_http_proxy_finalize_request(p, 0);
return;
}
- ep->cachable = p->cachable;
-
ep->temp_file->file.fd = NGX_INVALID_FILE;
ep->temp_file->file.log = r->connection->log;
ep->temp_file->path = p->lcf->temp_path;