comparison src/http/ngx_http_header_filter.c @ 99:a059e1aa65d4

nginx-0.0.1-2003-06-02-19:24:30 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Jun 2003 15:24:30 +0000
parents c9b243802a17
children 7ebc8b7fb816
comparison
equal deleted inserted replaced
98:c9b243802a17 99:a059e1aa65d4
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 4 #include <ngx_http.h>
5 #include <nginx.h> 5 #include <nginx.h>
6
7 #include <ngx_http.h>
8 #include <ngx_http_write_filter.h>
9 6
10 7
11 static int ngx_http_header_filter_init(ngx_pool_t *pool); 8 static int ngx_http_header_filter_init(ngx_pool_t *pool);
12 static int ngx_http_header_filter(ngx_http_request_t *r); 9 static int ngx_http_header_filter(ngx_http_request_t *r);
13 10
50 #if 0 47 #if 0
51 ngx_null_string, /* "300 Multiple Choices" */ 48 ngx_null_string, /* "300 Multiple Choices" */
52 #endif 49 #endif
53 50
54 ngx_string("301 Moved Permanently"), 51 ngx_string("301 Moved Permanently"),
52 #if 0
55 ngx_string("302 Moved Temporarily"), 53 ngx_string("302 Moved Temporarily"),
54 #else
55 ngx_string("302 Found"),
56 #endif
56 ngx_null_string, /* "303 See Other" */ 57 ngx_null_string, /* "303 See Other" */
57 ngx_string("304 Not Modified"), 58 ngx_string("304 Not Modified"),
58 59
59 ngx_string("400 Bad Request"), 60 ngx_string("400 Bad Request"),
60 ngx_string("401 Unauthorized"), 61 ngx_string("401 Unauthorized"),
85 86
86 87
87 88
88 static int ngx_http_header_filter(ngx_http_request_t *r) 89 static int ngx_http_header_filter(ngx_http_request_t *r)
89 { 90 {
90 int len, status, text, i; 91 int len, status, i;
91 time_t ims; 92 time_t ims;
92 ngx_hunk_t *h; 93 ngx_hunk_t *h;
93 ngx_chain_t *ch; 94 ngx_chain_t *ch;
94 ngx_table_elt_t *header; 95 ngx_table_elt_t *header;
96 ngx_http_range_t *range;
95 97
96 if (r->http_version < NGX_HTTP_VERSION_10) { 98 if (r->http_version < NGX_HTTP_VERSION_10) {
97 return NGX_OK; 99 return NGX_OK;
98 } 100 }
99 101
168 } else { 170 } else {
169 /* "Date: ... \r\n" */ 171 /* "Date: ... \r\n" */
170 len += 37; 172 len += 37;
171 } 173 }
172 174
175 if (r->headers_out.content_range && r->headers_out.content_range->value.len)
176 {
177 len += 15 + r->headers_out.content_range->value.len + 2;
178 }
179
173 if (r->headers_out.content_length >= 0) { 180 if (r->headers_out.content_length >= 0) {
174 /* "Content-Length: ... \r\n", 2^64 is 20 characters */ 181 /* "Content-Length: ... \r\n", 2^64 is 20 characters */
175 len += 48; 182 len += 48;
176 } 183 }
177 184
178 text = 0;
179 if (r->headers_out.content_type && r->headers_out.content_type->value.len) { 185 if (r->headers_out.content_type && r->headers_out.content_type->value.len) {
180 r->headers_out.content_type->key.len = 0; 186 r->headers_out.content_type->key.len = 0;
181 len += 16 + r->headers_out.content_type->value.len; 187 len += 16 + r->headers_out.content_type->value.len;
182 if (ngx_strncasecmp(r->headers_out.content_type->value.data, 188
183 "text/", 5) == 0) { 189 if (r->headers_out.charset.len) {
184 text = 1; 190 /* "; charset= ... " */
185 /* "; charset=koi8-r" */ 191 len += 10 + r->headers_out.charset.len;
186 len += 16;
187 } 192 }
188 } 193 }
189 194
190 if (r->headers_out.location 195 if (r->headers_out.location
191 && r->headers_out.location->value.len 196 && r->headers_out.location->value.len
208 } else if (r->headers_out.last_modified_time != -1) { 213 } else if (r->headers_out.last_modified_time != -1) {
209 /* "Last-Modified: ... \r\n" */ 214 /* "Last-Modified: ... \r\n" */
210 len += 46; 215 len += 46;
211 } 216 }
212 217
218 if (r->chunked) {
219 /* "Transfer-Encoding: chunked\r\n" */
220 len += 28;
221 }
222
213 if (r->keepalive == 0) { 223 if (r->keepalive == 0) {
214 /* "Connection: close\r\n" */ 224 /* "Connection: close\r\n" */
215 len += 19; 225 len += 19;
216 } else { 226 } else {
217 /* "Connection: keep-alive\r\n" */ 227 /* "Connection: keep-alive\r\n" */
248 } 258 }
249 259
250 if (!(r->headers_out.date && r->headers_out.date->key.len)) { 260 if (!(r->headers_out.date && r->headers_out.date->key.len)) {
251 h->last = ngx_cpymem(h->last, "Date: ", 6); 261 h->last = ngx_cpymem(h->last, "Date: ", 6);
252 h->last += ngx_http_get_time(h->last, time(NULL)); 262 h->last += ngx_http_get_time(h->last, time(NULL));
263 *(h->last++) = CR; *(h->last++) = LF;
264 }
265
266
267 if (r->headers_out.content_range && r->headers_out.content_range->value.len)
268 {
269 h->last = ngx_cpymem(h->last, "Content-Range: ", 15);
270 h->last = ngx_cpymem(h->last, r->headers_out.content_range->value.data,
271 r->headers_out.content_range->value.len);
253 *(h->last++) = CR; *(h->last++) = LF; 272 *(h->last++) = CR; *(h->last++) = LF;
254 } 273 }
255 274
256 /* 2^64 is 20 characters */ 275 /* 2^64 is 20 characters */
257 if (r->headers_out.content_length >= 0) { 276 if (r->headers_out.content_length >= 0) {
261 } 280 }
262 281
263 if (r->headers_out.content_type && r->headers_out.content_type->value.len) { 282 if (r->headers_out.content_type && r->headers_out.content_type->value.len) {
264 h->last = ngx_cpymem(h->last, "Content-Type: ", 14); 283 h->last = ngx_cpymem(h->last, "Content-Type: ", 14);
265 h->last = ngx_cpymem(h->last, r->headers_out.content_type->value.data, 284 h->last = ngx_cpymem(h->last, r->headers_out.content_type->value.data,
266 r->headers_out.content_type->value.len); 285 r->headers_out.content_type->value.len);
267 286
268 if (text) { 287 if (r->headers_out.charset.len) {
269 h->last = ngx_cpymem(h->last, "; charset=koi8-r", 16); 288 h->last = ngx_cpymem(h->last, "; charset=", 10);
289 h->last = ngx_cpymem(h->last, r->headers_out.charset.data,
290 r->headers_out.charset.len);
270 } 291 }
271 292
272 *(h->last++) = CR; *(h->last++) = LF; 293 *(h->last++) = CR; *(h->last++) = LF;
273 } 294 }
274 295
297 h->last += ngx_http_get_time(h->last, 318 h->last += ngx_http_get_time(h->last,
298 r->headers_out.last_modified_time); 319 r->headers_out.last_modified_time);
299 *(h->last++) = CR; *(h->last++) = LF; 320 *(h->last++) = CR; *(h->last++) = LF;
300 } 321 }
301 322
323 if (r->chunked) {
324 h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF, 28);
325 }
326
302 if (r->keepalive == 0) { 327 if (r->keepalive == 0) {
303 h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19); 328 h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
304 329
305 } else { 330 } else {
306 h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24); 331 h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);