diff src/http/ngx_http_core_module.c @ 2138:fb3b084e7d42

test Content-Type via hash: *) ngx_http_test_content_type() *) ngx_http_types_slot() *) ngx_http_merge_types()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 04 Aug 2008 11:29:09 +0000
parents 7a7c9e9024dd
children e9420c1b6f25
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1302,6 +1302,44 @@ 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)
 {