Mercurial > hg > nginx
comparison src/http/modules/ngx_http_static_module.c @ 2344:2eaf0d8f2990 stable-0.6
r2039 merge:
add args in redirect to a directory
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 27 Nov 2008 14:02:52 +0000 |
parents | d4df1c875351 |
children |
comparison
equal
deleted
inserted
replaced
2343:81901d359d98 | 2344:2eaf0d8f2990 |
---|---|
46 | 46 |
47 static ngx_int_t | 47 static ngx_int_t |
48 ngx_http_static_handler(ngx_http_request_t *r) | 48 ngx_http_static_handler(ngx_http_request_t *r) |
49 { | 49 { |
50 u_char *last, *location; | 50 u_char *last, *location; |
51 size_t root; | 51 size_t root, len; |
52 ngx_str_t path; | 52 ngx_str_t path; |
53 ngx_int_t rc; | 53 ngx_int_t rc; |
54 ngx_uint_t level; | 54 ngx_uint_t level; |
55 ngx_log_t *log; | 55 ngx_log_t *log; |
56 ngx_buf_t *b; | 56 ngx_buf_t *b; |
142 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t)); | 142 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t)); |
143 if (r->headers_out.location == NULL) { | 143 if (r->headers_out.location == NULL) { |
144 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 144 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
145 } | 145 } |
146 | 146 |
147 if (!clcf->alias && clcf->root_lengths == NULL) { | 147 len = r->uri.len + 1; |
148 | |
149 if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) { | |
148 location = path.data + clcf->root.len; | 150 location = path.data + clcf->root.len; |
149 | 151 |
152 *last = '/'; | |
153 | |
150 } else { | 154 } else { |
151 location = ngx_palloc(r->pool, r->uri.len + 1); | 155 if (r->args.len) { |
156 len += r->args.len + 1; | |
157 } | |
158 | |
159 location = ngx_palloc(r->pool, len); | |
152 if (location == NULL) { | 160 if (location == NULL) { |
153 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 161 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
154 } | 162 } |
155 | 163 |
156 last = ngx_copy(location, r->uri.data, r->uri.len); | 164 last = ngx_copy(location, r->uri.data, r->uri.len); |
157 } | 165 |
158 | 166 *last = '/'; |
159 *last = '/'; | 167 |
168 if (r->args.len) { | |
169 *++last = '?'; | |
170 ngx_memcpy(++last, r->args.data, r->args.len); | |
171 } | |
172 } | |
160 | 173 |
161 /* | 174 /* |
162 * we do not need to set the r->headers_out.location->hash and | 175 * we do not need to set the r->headers_out.location->hash and |
163 * r->headers_out.location->key fields | 176 * r->headers_out.location->key fields |
164 */ | 177 */ |
165 | 178 |
166 r->headers_out.location->value.len = r->uri.len + 1; | 179 r->headers_out.location->value.len = len; |
167 r->headers_out.location->value.data = location; | 180 r->headers_out.location->value.data = location; |
168 | 181 |
169 return NGX_HTTP_MOVED_PERMANENTLY; | 182 return NGX_HTTP_MOVED_PERMANENTLY; |
170 } | 183 } |
171 | 184 |