comparison src/http/modules/ngx_http_static_module.c @ 2038:93a0d80fdce6

add args in redirect to a directory
author Igor Sysoev <igor@sysoev.ru>
date Mon, 26 May 2008 18:57:43 +0000
parents 0b5b94805d26
children 2a92804f4109
comparison
equal deleted inserted replaced
2037:aee889ff25ea 2038:93a0d80fdce6
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;
148 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t)); 148 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
149 if (r->headers_out.location == NULL) { 149 if (r->headers_out.location == NULL) {
150 return NGX_HTTP_INTERNAL_SERVER_ERROR; 150 return NGX_HTTP_INTERNAL_SERVER_ERROR;
151 } 151 }
152 152
153 if (!clcf->alias && clcf->root_lengths == NULL) { 153 len = r->uri.len + 1;
154
155 if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) {
154 location = path.data + clcf->root.len; 156 location = path.data + clcf->root.len;
155 157
158 *last = '/';
159
156 } else { 160 } else {
157 location = ngx_palloc(r->pool, r->uri.len + 1); 161 if (r->args.len) {
162 len += r->args.len + 1;
163 }
164
165 location = ngx_palloc(r->pool, len);
158 if (location == NULL) { 166 if (location == NULL) {
159 return NGX_HTTP_INTERNAL_SERVER_ERROR; 167 return NGX_HTTP_INTERNAL_SERVER_ERROR;
160 } 168 }
161 169
162 last = ngx_copy(location, r->uri.data, r->uri.len); 170 last = ngx_copy(location, r->uri.data, r->uri.len);
163 } 171
164 172 *last = '/';
165 *last = '/'; 173
174 if (r->args.len) {
175 *++last = '?';
176 ngx_memcpy(++last, r->args.data, r->args.len);
177 }
178 }
166 179
167 /* 180 /*
168 * we do not need to set the r->headers_out.location->hash and 181 * we do not need to set the r->headers_out.location->hash and
169 * r->headers_out.location->key fields 182 * r->headers_out.location->key fields
170 */ 183 */
171 184
172 r->headers_out.location->value.len = r->uri.len + 1; 185 r->headers_out.location->value.len = len;
173 r->headers_out.location->value.data = location; 186 r->headers_out.location->value.data = location;
174 187
175 return NGX_HTTP_MOVED_PERMANENTLY; 188 return NGX_HTTP_MOVED_PERMANENTLY;
176 } 189 }
177 190