changeset 3635:c0113b6648de

use ngx_http_send_response() in empty_gif
author Igor Sysoev <igor@sysoev.ru>
date Fri, 18 Jun 2010 15:17:07 +0000
parents 40e356cf4176
children 446f611b0a79
files src/http/modules/ngx_http_empty_gif_module.c
diffstat 1 files changed, 9 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_empty_gif_module.c
+++ b/src/http/modules/ngx_http_empty_gif_module.c
@@ -105,12 +105,14 @@ ngx_module_t  ngx_http_empty_gif_module 
 };
 
 
+static ngx_str_t  ngx_http_gif_type = ngx_string("image/gif");
+
+
 static ngx_int_t
 ngx_http_empty_gif_handler(ngx_http_request_t *r)
 {
-    ngx_int_t     rc;
-    ngx_buf_t    *b;
-    ngx_chain_t   out;
+    ngx_int_t                 rc;
+    ngx_http_complex_value_t  cv;
 
     if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
         return NGX_HTTP_NOT_ALLOWED;
@@ -122,41 +124,13 @@ ngx_http_empty_gif_handler(ngx_http_requ
         return rc;
     }
 
-    r->headers_out.content_type_len = sizeof("image/gif") - 1;
-    ngx_str_set(&r->headers_out.content_type, "image/gif");
-
-    if (r->method == NGX_HTTP_HEAD) {
-        r->headers_out.status = NGX_HTTP_OK;
-        r->headers_out.content_length_n = sizeof(ngx_empty_gif);
-        r->headers_out.last_modified_time = 23349600;
-
-        return ngx_http_send_header(r);
-    }
+    ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
 
-    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
-    if (b == NULL) {
-        return NGX_HTTP_INTERNAL_SERVER_ERROR;
-    }
-
-    out.buf = b;
-    out.next = NULL;
-
-    b->pos = ngx_empty_gif;
-    b->last = ngx_empty_gif + sizeof(ngx_empty_gif);
-    b->memory = 1;
-    b->last_buf = 1;
-
-    r->headers_out.status = NGX_HTTP_OK;
-    r->headers_out.content_length_n = sizeof(ngx_empty_gif);
+    cv.value.len = sizeof(ngx_empty_gif);
+    cv.value.data = ngx_empty_gif;
     r->headers_out.last_modified_time = 23349600;
 
-    rc = ngx_http_send_header(r);
-
-    if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
-        return rc;
-    }
-
-    return ngx_http_output_filter(r, &out);
+    return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
 }