use ngx_http_send_response() in empty_gif

This commit is contained in:
Igor Sysoev 2010-06-18 15:17:07 +00:00
parent b2ee47c0c7
commit 082d9965a3

View File

@ -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_request_t *r)
return rc;
}
r->headers_out.content_type_len = sizeof("image/gif") - 1;
ngx_str_set(&r->headers_out.content_type, "image/gif");
ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
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);
}
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);
}