diff options
author | Igor Sysoev <igor@sysoev.ru> | 2003-11-18 21:34:08 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2003-11-18 21:34:08 +0000 |
commit | 1b138ed141c0bdb0c9944c1ae70e53682ed2d035 (patch) | |
tree | c5b4cabecced530570f4a2d6a93cc7d5fc8e044e /src/http/modules/proxy/ngx_http_proxy_header.c | |
parent | 222a2adf40eb25ff613c251f15032f1e39d7f609 (diff) | |
download | nginx-1b138ed141c0bdb0c9944c1ae70e53682ed2d035.tar.gz nginx-1b138ed141c0bdb0c9944c1ae70e53682ed2d035.zip |
nginx-0.0.1-2003-11-19-00:34:08 import
Diffstat (limited to 'src/http/modules/proxy/ngx_http_proxy_header.c')
-rw-r--r-- | src/http/modules/proxy/ngx_http_proxy_header.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c index 4dda797bf..76d33211c 100644 --- a/src/http/modules/proxy/ngx_http_proxy_header.c +++ b/src/http/modules/proxy/ngx_http_proxy_header.c @@ -5,6 +5,9 @@ #include <ngx_http_proxy_handler.h> +static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, + ngx_table_elt_t *loc); + int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, ngx_http_proxy_headers_in_t *headers_in) { @@ -36,6 +39,16 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, if (&h[i] == headers_in->server && !p->lcf->pass_server) { continue; } + + if (&h[i] == headers_in->location) { + if (ngx_http_proxy_rewrite_location_header(p, &h[i]) + == NGX_ERROR) + { + return NGX_ERROR; + } + + continue; + } } if (&h[i] == headers_in->content_type) { @@ -79,3 +92,47 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, return NGX_OK; } + + +static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, + ngx_table_elt_t *loc) +{ + char *last; + ngx_http_request_t *r; + ngx_http_proxy_upstream_conf_t *uc; + + r = p->request; + uc = p->lcf->upstream; + + r->headers_out.location = ngx_http_add_header(&r->headers_out, + ngx_http_headers_out); + if (r->headers_out.location == NULL) { + return NGX_ERROR; + } + + if (uc->url.len > loc->value.len + || ngx_rstrncmp(loc->value.data, uc->url.data, uc->url.len) != 0) + { + *r->headers_out.location = *loc; + return NGX_OK; + } + + /* TODO: proxy_reverse */ + + r->headers_out.location->value.len = uc->location->len + + (loc->value.len - uc->url.len) + 1; + r->headers_out.location->value.data = + ngx_palloc(r->pool, r->headers_out.location->value.len); + + if (r->headers_out.location->value.data == NULL) { + return NGX_ERROR; + } + + last = ngx_cpymem(r->headers_out.location->value.data, + uc->location->data, uc->location->len); + + ngx_cpystrn(last, loc->value.data + uc->url.len, + loc->value.len - uc->url.len + 1); + + return NGX_OK; +} |