comparison src/http/modules/ngx_http_empty_gif_module.c @ 635:e67b227c8dbb default tip

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:07:55 +0400
parents 4d3e880ce86c
children
comparison
equal deleted inserted replaced
578:f3a9e57d2e17 635:e67b227c8dbb
103 NULL, /* exit master */ 103 NULL, /* exit master */
104 NGX_MODULE_V1_PADDING 104 NGX_MODULE_V1_PADDING
105 }; 105 };
106 106
107 107
108 static ngx_str_t ngx_http_gif_type = ngx_string("image/gif");
109
110
108 static ngx_int_t 111 static ngx_int_t
109 ngx_http_empty_gif_handler(ngx_http_request_t *r) 112 ngx_http_empty_gif_handler(ngx_http_request_t *r)
110 { 113 {
111 ngx_int_t rc; 114 ngx_int_t rc;
112 ngx_buf_t *b; 115 ngx_http_complex_value_t cv;
113 ngx_chain_t out;
114 116
115 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { 117 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
116 return NGX_HTTP_NOT_ALLOWED; 118 return NGX_HTTP_NOT_ALLOWED;
117 } 119 }
118 120
120 122
121 if (rc != NGX_OK) { 123 if (rc != NGX_OK) {
122 return rc; 124 return rc;
123 } 125 }
124 126
125 r->headers_out.content_type_len = sizeof("image/gif") - 1; 127 ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
126 r->headers_out.content_type.len = sizeof("image/gif") - 1;
127 r->headers_out.content_type.data = (u_char *) "image/gif";
128 128
129 if (r->method == NGX_HTTP_HEAD) { 129 cv.value.len = sizeof(ngx_empty_gif);
130 r->headers_out.status = NGX_HTTP_OK; 130 cv.value.data = ngx_empty_gif;
131 r->headers_out.content_length_n = sizeof(ngx_empty_gif);
132 r->headers_out.last_modified_time = 23349600;
133
134 return ngx_http_send_header(r);
135 }
136
137 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
138 if (b == NULL) {
139 return NGX_HTTP_INTERNAL_SERVER_ERROR;
140 }
141
142 out.buf = b;
143 out.next = NULL;
144
145 b->pos = ngx_empty_gif;
146 b->last = ngx_empty_gif + sizeof(ngx_empty_gif);
147 b->memory = 1;
148 b->last_buf = 1;
149
150 r->headers_out.status = NGX_HTTP_OK;
151 r->headers_out.content_length_n = sizeof(ngx_empty_gif);
152 r->headers_out.last_modified_time = 23349600; 131 r->headers_out.last_modified_time = 23349600;
153 132
154 rc = ngx_http_send_header(r); 133 return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
155
156 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
157 return rc;
158 }
159
160 return ngx_http_output_filter(r, &out);
161 } 134 }
162 135
163 136
164 static char * 137 static char *
165 ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 138 ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)