diff src/http/ngx_http_core_module.c @ 392:34fb3a573548 NGINX_0_7_8

nginx 0.7.8 *) Feature: the ngx_http_xslt_module. *) Feature: the "$arg_..." variables. *) Feature: Solaris directio support. Thanks to Ivan Debnar. *) Bugfix: now if FastCGI server sends a "Location" header line without status line, then nginx uses 302 status code. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 04 Aug 2008 00:00:00 +0400
parents 0b6053502c55
children 9d81578d04bb
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1302,10 +1302,48 @@ ngx_http_core_send_continue(ngx_http_req
 }
 
 
+void *
+ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
+{
+    u_char       c, *p;
+    ngx_uint_t   i, hash;
+
+    if (r->headers_out.content_type.len == 0) {
+        return NULL;
+    }
+
+    if (r->headers_out.content_type_lowcase == NULL) {
+
+        p = ngx_pnalloc(r->pool, r->headers_out.content_type_len);
+
+        if (p == NULL) {
+            return NULL;
+        }
+
+        r->headers_out.content_type_lowcase = p;
+
+        hash = 0;
+
+        for (i = 0; i < r->headers_out.content_type_len; i++) {
+            c = ngx_tolower(r->headers_out.content_type.data[i]);
+            hash = ngx_hash(hash, c);
+            *p++ = c;
+        }
+
+        r->headers_out.content_type_hash = hash;
+    }
+
+    return ngx_hash_find(types_hash,
+                         r->headers_out.content_type_hash,
+                         r->headers_out.content_type_lowcase,
+                         r->headers_out.content_type_len);
+}
+
+
 ngx_int_t
 ngx_http_set_content_type(ngx_http_request_t *r)
 {
-    u_char                     c, *p, *exten;
+    u_char                     c, *exten;
     ngx_str_t                 *type;
     ngx_uint_t                 i, hash;
     ngx_http_core_loc_conf_t  *clcf;
@@ -1325,19 +1363,12 @@ ngx_http_set_content_type(ngx_http_reque
 
             if (c >= 'A' && c <= 'Z') {
 
-                p = ngx_pnalloc(r->pool, r->exten.len);
-                if (p == NULL) {
+                exten = ngx_pnalloc(r->pool, r->exten.len);
+                if (exten == NULL) {
                     return NGX_HTTP_INTERNAL_SERVER_ERROR;
                 }
 
-                hash = 0;
-                exten = p;
-
-                for (i = 0; i < r->exten.len; i++) {
-                    c = ngx_tolower(r->exten.data[i]);
-                    hash = ngx_hash(hash, c);
-                    *p++ = c;
-                }
+                hash = ngx_hash_strlow(exten, r->exten.data, r->exten.len);
 
                 r->exten.data = exten;
 
@@ -2316,7 +2347,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_c
     ngx_http_core_loc_conf_t *lcf = conf;
 
     ngx_str_t       *value, *content_type, *old, file;
-    ngx_uint_t       i, n;
+    ngx_uint_t       i, n, hash;
     ngx_hash_key_t  *type;
 
     value = cf->args->elts;
@@ -2342,9 +2373,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_c
 
     for (i = 1; i < cf->args->nelts; i++) {
 
-        for (n = 0; n < value[i].len; n++) {
-            value[i].data[n] = ngx_tolower(value[i].data[n]);
-        }
+        hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
 
         type = lcf->types->elts;
         for (n = 0; n < lcf->types->nelts; n++) {
@@ -2368,7 +2397,7 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_c
         }
 
         type->key = value[i];
-        type->key_hash = ngx_hash_key(value[i].data, value[i].len);
+        type->key_hash = hash;
         type->value = content_type;
     }