comparison src/http/ngx_http_core_module.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 4c698194c56d
children 71ce40b3c37b
comparison
equal deleted inserted replaced
189:c966c09be66b 190:02a715e85df1
367 367
368 368
369 int ngx_http_find_location_config(ngx_http_request_t *r) 369 int ngx_http_find_location_config(ngx_http_request_t *r)
370 { 370 {
371 int i, rc; 371 int i, rc;
372 ngx_str_t *auto_redirect;
372 ngx_http_core_loc_conf_t *clcf, **clcfp; 373 ngx_http_core_loc_conf_t *clcf, **clcfp;
373 ngx_http_core_srv_conf_t *cscf; 374 ngx_http_core_srv_conf_t *cscf;
374 375
375 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 376 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
377 auto_redirect = NULL;
376 378
377 clcfp = cscf->locations.elts; 379 clcfp = cscf->locations.elts;
378 for (i = 0; i < cscf->locations.nelts; i++) { 380 for (i = 0; i < cscf->locations.nelts; i++) {
379 #if 0 381 #if 0
380 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data); 382 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data);
381 #endif 383 #endif
384 if (clcfp[i]->auto_redirect
385 && r->uri.len == clcfp[i]->name.len - 1
386 && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
387 clcfp[i]->name.len - 1) == 0)
388 {
389 auto_redirect = &clcfp[i]->name;
390 continue;
391 }
392
382 if (r->uri.len < clcfp[i]->name.len) { 393 if (r->uri.len < clcfp[i]->name.len) {
383 continue; 394 continue;
384 } 395 }
385 396
386 rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len); 397 rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
387 398
388 if (rc < 0) { 399 if (rc < 0) {
400 /* locations are lexicographically sorted */
389 break; 401 break;
390 } 402 }
391 403
392 if (rc == 0) { 404 if (rc == 0) {
393 r->loc_conf = clcfp[i]->loc_conf; 405 r->loc_conf = clcfp[i]->loc_conf;
402 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { 414 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) {
403 r->sendfile = 0; 415 r->sendfile = 0;
404 416
405 } else { 417 } else {
406 r->sendfile = 1; 418 r->sendfile = 1;
419 }
420
421 if (auto_redirect) {
422 if (!(r->headers_out.location =
423 ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
424 {
425 return NGX_HTTP_INTERNAL_SERVER_ERROR;
426 }
427
428 #if 0
429 r->headers_out.location->key.len = 8;
430 r->headers_out.location->key.data = "Location";
431 #endif
432 r->headers_out.location->value = *auto_redirect;
433
434 return NGX_HTTP_MOVED_PERMANENTLY;
407 } 435 }
408 436
409 if (clcf->handler) { 437 if (clcf->handler) {
410 /* 438 /*
411 * if the location already has content handler then skip 439 * if the location already has content handler then skip