comparison src/http/modules/ngx_http_empty_gif_module.c @ 580:4d3e880ce86c NGINX_0_8_42

nginx 0.8.42 *) Change: now nginx tests locations given by regular expressions, if request was matched exactly by a location given by a prefix string. The previous behavior has been introduced in 0.7.1. *) Feature: the ngx_http_scgi_module. Thanks to Manlio Perillo. *) Feature: a text answer may be added to a "return" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 21 Jun 2010 00:00:00 +0400
parents 8246d8a2c2be
children d3cf6c6b0043
comparison
equal deleted inserted replaced
579:c570633043e7 580:4d3e880ce86c
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 ngx_str_set(&r->headers_out.content_type, "image/gif");
127 128
128 if (r->method == NGX_HTTP_HEAD) { 129 cv.value.len = sizeof(ngx_empty_gif);
129 r->headers_out.status = NGX_HTTP_OK; 130 cv.value.data = ngx_empty_gif;
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);
151 r->headers_out.last_modified_time = 23349600; 131 r->headers_out.last_modified_time = 23349600;
152 132
153 rc = ngx_http_send_header(r); 133 return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
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);
160 } 134 }
161 135
162 136
163 static char * 137 static char *
164 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)