Mercurial > hg > nginx
comparison src/http/modules/proxy/ngx_http_proxy_header.c @ 190:02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 18 Nov 2003 21:34:08 +0000 |
parents | caa57ddf6d77 |
children | 0b67be7d4489 |
comparison
equal
deleted
inserted
replaced
189:c966c09be66b | 190:02a715e85df1 |
---|---|
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_http.h> | 4 #include <ngx_http.h> |
5 #include <ngx_http_proxy_handler.h> | 5 #include <ngx_http_proxy_handler.h> |
6 | 6 |
7 | |
8 static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, | |
9 ngx_table_elt_t *loc); | |
7 | 10 |
8 int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, | 11 int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, |
9 ngx_http_proxy_headers_in_t *headers_in) | 12 ngx_http_proxy_headers_in_t *headers_in) |
10 { | 13 { |
11 int i; | 14 int i; |
32 { | 35 { |
33 continue; | 36 continue; |
34 } | 37 } |
35 | 38 |
36 if (&h[i] == headers_in->server && !p->lcf->pass_server) { | 39 if (&h[i] == headers_in->server && !p->lcf->pass_server) { |
40 continue; | |
41 } | |
42 | |
43 if (&h[i] == headers_in->location) { | |
44 if (ngx_http_proxy_rewrite_location_header(p, &h[i]) | |
45 == NGX_ERROR) | |
46 { | |
47 return NGX_ERROR; | |
48 } | |
49 | |
37 continue; | 50 continue; |
38 } | 51 } |
39 } | 52 } |
40 | 53 |
41 if (&h[i] == headers_in->content_type) { | 54 if (&h[i] == headers_in->content_type) { |
77 } | 90 } |
78 } | 91 } |
79 | 92 |
80 return NGX_OK; | 93 return NGX_OK; |
81 } | 94 } |
95 | |
96 | |
97 static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, | |
98 ngx_table_elt_t *loc) | |
99 { | |
100 char *last; | |
101 ngx_http_request_t *r; | |
102 ngx_http_proxy_upstream_conf_t *uc; | |
103 | |
104 r = p->request; | |
105 uc = p->lcf->upstream; | |
106 | |
107 r->headers_out.location = ngx_http_add_header(&r->headers_out, | |
108 ngx_http_headers_out); | |
109 if (r->headers_out.location == NULL) { | |
110 return NGX_ERROR; | |
111 } | |
112 | |
113 if (uc->url.len > loc->value.len | |
114 || ngx_rstrncmp(loc->value.data, uc->url.data, uc->url.len) != 0) | |
115 { | |
116 *r->headers_out.location = *loc; | |
117 return NGX_OK; | |
118 } | |
119 | |
120 /* TODO: proxy_reverse */ | |
121 | |
122 r->headers_out.location->value.len = uc->location->len | |
123 + (loc->value.len - uc->url.len) + 1; | |
124 r->headers_out.location->value.data = | |
125 ngx_palloc(r->pool, r->headers_out.location->value.len); | |
126 | |
127 if (r->headers_out.location->value.data == NULL) { | |
128 return NGX_ERROR; | |
129 } | |
130 | |
131 last = ngx_cpymem(r->headers_out.location->value.data, | |
132 uc->location->data, uc->location->len); | |
133 | |
134 ngx_cpystrn(last, loc->value.data + uc->url.len, | |
135 loc->value.len - uc->url.len + 1); | |
136 | |
137 return NGX_OK; | |
138 } |