~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_empty_gif_module.c

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
4
5
 */
5
6
 
6
7
#include <ngx_config.h>
105
106
};
106
107
 
107
108
 
 
109
static ngx_str_t  ngx_http_gif_type = ngx_string("image/gif");
 
110
 
 
111
 
108
112
static ngx_int_t
109
113
ngx_http_empty_gif_handler(ngx_http_request_t *r)
110
114
{
111
 
    ngx_int_t     rc;
112
 
    ngx_buf_t    *b;
113
 
    ngx_chain_t   out;
 
115
    ngx_http_complex_value_t  cv;
114
116
 
115
117
    if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
116
118
        return NGX_HTTP_NOT_ALLOWED;
117
119
    }
118
120
 
119
 
    rc = ngx_http_discard_request_body(r);
120
 
 
121
 
    if (rc != NGX_OK) {
122
 
        return rc;
123
 
    }
124
 
 
125
 
    r->headers_out.content_type.len = sizeof("image/gif") - 1;
126
 
    r->headers_out.content_type.data = (u_char *) "image/gif";
127
 
 
128
 
    if (r->method == NGX_HTTP_HEAD) {
129
 
        r->headers_out.status = NGX_HTTP_OK;
130
 
        r->headers_out.content_length_n = sizeof(ngx_empty_gif);
131
 
        r->headers_out.last_modified_time = 23349600;
132
 
 
133
 
        return ngx_http_send_header(r);
134
 
    }
135
 
 
136
 
    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
137
 
    if (b == NULL) {
138
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
139
 
    }
140
 
 
141
 
    out.buf = b;
142
 
    out.next = NULL;
143
 
 
144
 
    b->pos = ngx_empty_gif;
145
 
    b->last = ngx_empty_gif + sizeof(ngx_empty_gif);
146
 
    b->memory = 1;
147
 
    b->last_buf = 1;
148
 
 
149
 
    r->headers_out.status = NGX_HTTP_OK;
150
 
    r->headers_out.content_length_n = sizeof(ngx_empty_gif);
 
121
    ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
 
122
 
 
123
    cv.value.len = sizeof(ngx_empty_gif);
 
124
    cv.value.data = ngx_empty_gif;
151
125
    r->headers_out.last_modified_time = 23349600;
152
126
 
153
 
    rc = ngx_http_send_header(r);
154
 
 
155
 
    if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
156
 
        return rc;
157
 
    }
158
 
 
159
 
    return ngx_http_output_filter(r, &out);
 
127
    return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
160
128
}
161
129
 
162
130