Mercurial > hg > nginx
comparison src/http/modules/ngx_http_chunked_filter_module.c @ 501:d4ea69372b94 release-0.1.25
nginx-0.1.25-RELEASE import
*) Bugfix: nginx did run on Linux parisc.
*) Feature: nginx now does not start under FreeBSD if the sysctl
kern.ipc.somaxconn value is too big.
*) Bugfix: if a request was internally redirected by the
ngx_http_index_module module to the ngx_http_proxy_module or
ngx_http_fastcgi_module modules, then the index file was not closed
after request completion.
*) Feature: the "proxy_pass" can be used in location with regular
expression.
*) Feature: the ngx_http_rewrite_filter_module module supports the
condition like "if ($HTTP_USER_AGENT ~ MSIE)".
*) Bugfix: nginx started too slow if the large number of addresses and
text values were used in the "geo" directive.
*) Change: a variable name must be declared as "$name" in the "geo"
directive. The previous variant without "$" is still supported, but
will be removed soon.
*) Feature: the "%{VARIABLE}v" logging parameter.
*) Feature: the "set $name value" directive.
*) Bugfix: gcc 4.0 compatibility.
*) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 12:38:37 +0000 |
parents | src/http/modules/ngx_http_chunked_filter.c@621229427cba |
children | 9b8c906f6e63 |
comparison
equal
deleted
inserted
replaced
500:9a0f304470f5 | 501:d4ea69372b94 |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 static ngx_int_t ngx_http_chunked_filter_init(ngx_cycle_t *cycle); | |
13 | |
14 | |
15 static ngx_http_module_t ngx_http_chunked_filter_module_ctx = { | |
16 NULL, /* pre conf */ | |
17 | |
18 NULL, /* create main configuration */ | |
19 NULL, /* init main configuration */ | |
20 | |
21 NULL, /* create server configuration */ | |
22 NULL, /* merge server configuration */ | |
23 | |
24 NULL, /* create location configuration */ | |
25 NULL, /* merge location configuration */ | |
26 }; | |
27 | |
28 | |
29 ngx_module_t ngx_http_chunked_filter_module = { | |
30 NGX_MODULE, | |
31 &ngx_http_chunked_filter_module_ctx, /* module context */ | |
32 NULL, /* module directives */ | |
33 NGX_HTTP_MODULE, /* module type */ | |
34 ngx_http_chunked_filter_init, /* init module */ | |
35 NULL /* init process */ | |
36 }; | |
37 | |
38 | |
39 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
40 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
41 | |
42 | |
43 static ngx_int_t | |
44 ngx_http_chunked_header_filter(ngx_http_request_t *r) | |
45 { | |
46 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) { | |
47 return ngx_http_next_header_filter(r); | |
48 } | |
49 | |
50 if (r->headers_out.content_length_n == -1) { | |
51 if (r->http_version < NGX_HTTP_VERSION_11) { | |
52 r->keepalive = 0; | |
53 | |
54 } else { | |
55 r->chunked = 1; | |
56 } | |
57 } | |
58 | |
59 return ngx_http_next_header_filter(r); | |
60 } | |
61 | |
62 | |
63 static ngx_int_t | |
64 ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
65 { | |
66 u_char *chunk; | |
67 off_t size; | |
68 ngx_buf_t *b; | |
69 ngx_chain_t out, tail, *cl, *tl, **ll; | |
70 | |
71 if (in == NULL || !r->chunked || r->header_only) { | |
72 return ngx_http_next_body_filter(r, in); | |
73 } | |
74 | |
75 out.buf = NULL; | |
76 ll = &out.next; | |
77 | |
78 size = 0; | |
79 cl = in; | |
80 | |
81 for ( ;; ) { | |
82 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
83 "http chunk: %d", ngx_buf_size(cl->buf)); | |
84 | |
85 size += ngx_buf_size(cl->buf); | |
86 | |
87 if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) { | |
88 | |
89 tl = ngx_alloc_chain_link(r->pool); | |
90 if (tl == NULL) { | |
91 return NGX_ERROR; | |
92 } | |
93 | |
94 tl->buf = cl->buf; | |
95 *ll = tl; | |
96 ll = &tl->next; | |
97 } | |
98 | |
99 if (cl->next == NULL) { | |
100 break; | |
101 } | |
102 | |
103 cl = cl->next; | |
104 } | |
105 | |
106 if (size) { | |
107 b = ngx_calloc_buf(r->pool); | |
108 if (b == NULL) { | |
109 return NGX_ERROR; | |
110 } | |
111 | |
112 /* the "0000000000000000" is 64-bit hexadimal string */ | |
113 | |
114 chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1); | |
115 if (chunk == NULL) { | |
116 return NGX_ERROR; | |
117 } | |
118 | |
119 b->temporary = 1; | |
120 b->pos = chunk; | |
121 b->last = ngx_sprintf(chunk, "%xO" CRLF, size); | |
122 | |
123 out.buf = b; | |
124 } | |
125 | |
126 if (cl->buf->last_buf) { | |
127 b = ngx_calloc_buf(r->pool); | |
128 if (b == NULL) { | |
129 return NGX_ERROR; | |
130 } | |
131 | |
132 b->memory = 1; | |
133 b->last_buf = 1; | |
134 b->pos = (u_char *) CRLF "0" CRLF CRLF; | |
135 b->last = b->pos + 7; | |
136 | |
137 cl->buf->last_buf = 0; | |
138 | |
139 if (size == 0) { | |
140 b->pos += 2; | |
141 out.buf = b; | |
142 out.next = NULL; | |
143 | |
144 return ngx_http_next_body_filter(r, &out); | |
145 } | |
146 | |
147 } else { | |
148 if (size == 0) { | |
149 *ll = NULL; | |
150 return ngx_http_next_body_filter(r, out.next); | |
151 } | |
152 | |
153 b = ngx_calloc_buf(r->pool); | |
154 if (b == NULL) { | |
155 return NGX_ERROR; | |
156 } | |
157 | |
158 b->memory = 1; | |
159 b->pos = (u_char *) CRLF; | |
160 b->last = b->pos + 2; | |
161 } | |
162 | |
163 tail.buf = b; | |
164 tail.next = NULL; | |
165 *ll = &tail; | |
166 | |
167 return ngx_http_next_body_filter(r, &out); | |
168 } | |
169 | |
170 | |
171 static ngx_int_t | |
172 ngx_http_chunked_filter_init(ngx_cycle_t *cycle) | |
173 { | |
174 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
175 ngx_http_top_header_filter = ngx_http_chunked_header_filter; | |
176 | |
177 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
178 ngx_http_top_body_filter = ngx_http_chunked_body_filter; | |
179 | |
180 return NGX_OK; | |
181 } |