diff 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
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -369,16 +369,27 @@ static void ngx_http_run_phases(ngx_http
 int ngx_http_find_location_config(ngx_http_request_t *r)
 {
     int                            i, rc;
+    ngx_str_t                     *auto_redirect;
     ngx_http_core_loc_conf_t      *clcf, **clcfp;
     ngx_http_core_srv_conf_t      *cscf;
 
     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+    auto_redirect = NULL;
 
     clcfp = cscf->locations.elts;
     for (i = 0; i < cscf->locations.nelts; i++) {
 #if 0
 ngx_log_debug(r->connection->log, "trans: %s" _ clcfp[i]->name.data);
 #endif
+        if (clcfp[i]->auto_redirect
+            && r->uri.len == clcfp[i]->name.len - 1
+            && ngx_strncmp(r->uri.data, clcfp[i]->name.data,
+                           clcfp[i]->name.len - 1) == 0)
+        {
+            auto_redirect = &clcfp[i]->name;
+            continue;
+        }
+
         if (r->uri.len < clcfp[i]->name.len) {
             continue;
         }
@@ -386,6 +397,7 @@ ngx_log_debug(r->connection->log, "trans
         rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len);
 
         if (rc < 0) {
+            /* locations are lexicographically sorted */
             break;
         }
 
@@ -406,6 +418,22 @@ ngx_log_debug(r->connection->log, "trans
         r->sendfile = 1;
     }
 
+    if (auto_redirect) {
+        if (!(r->headers_out.location =
+                   ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
+        {
+            return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+#if 0
+        r->headers_out.location->key.len = 8;
+        r->headers_out.location->key.data = "Location";
+#endif
+        r->headers_out.location->value = *auto_redirect;
+
+        return NGX_HTTP_MOVED_PERMANENTLY;
+    }
+
     if (clcf->handler) {
         /*
          * if the location already has content handler then skip