Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_write_filter_module.c @ 50:72eb30262aac NGINX_0_1_25
nginx 0.1.25
*) 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 <http://sysoev.ru> |
---|---|
date | Sat, 19 Mar 2005 00:00:00 +0300 |
parents | |
children | 3050baa54a26 |
comparison
equal
deleted
inserted
replaced
49:93dabbc9efb9 | 50:72eb30262aac |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
14 ngx_chain_t *out; | |
15 } ngx_http_write_filter_ctx_t; | |
16 | |
17 | |
18 static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle); | |
19 | |
20 | |
21 ngx_http_module_t ngx_http_write_filter_module_ctx = { | |
22 NULL, /* pre conf */ | |
23 | |
24 NULL, /* create main configuration */ | |
25 NULL, /* init main configuration */ | |
26 | |
27 NULL, /* create server configuration */ | |
28 NULL, /* merge server configuration */ | |
29 | |
30 NULL, /* create location configuration */ | |
31 NULL, /* merge location configuration */ | |
32 }; | |
33 | |
34 | |
35 ngx_module_t ngx_http_write_filter_module = { | |
36 NGX_MODULE, | |
37 &ngx_http_write_filter_module_ctx, /* module context */ | |
38 NULL, /* module directives */ | |
39 NGX_HTTP_MODULE, /* module type */ | |
40 ngx_http_write_filter_init, /* init module */ | |
41 NULL /* init process */ | |
42 }; | |
43 | |
44 | |
45 ngx_int_t | |
46 ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
47 { | |
48 off_t size, sent; | |
49 ngx_uint_t last, flush; | |
50 ngx_chain_t *cl, *ln, **ll, *chain; | |
51 ngx_connection_t *c; | |
52 ngx_http_core_loc_conf_t *clcf; | |
53 ngx_http_write_filter_ctx_t *ctx; | |
54 | |
55 ctx = ngx_http_get_module_ctx(r->main ? r->main : r, | |
56 ngx_http_write_filter_module); | |
57 | |
58 if (ctx == NULL) { | |
59 | |
60 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_write_filter_ctx_t)); | |
61 if (ctx == NULL) { | |
62 return NGX_ERROR; | |
63 } | |
64 | |
65 ngx_http_set_ctx(r, ctx, ngx_http_write_filter_module); | |
66 } | |
67 | |
68 size = 0; | |
69 flush = 0; | |
70 last = 0; | |
71 ll = &ctx->out; | |
72 | |
73 /* find the size, the flush point and the last link of the saved chain */ | |
74 | |
75 for (cl = ctx->out; cl; cl = cl->next) { | |
76 ll = &cl->next; | |
77 | |
78 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0, | |
79 "write old buf t:%d f:%d %p, pos %p, size: %z " | |
80 "file: %O, size: %z", | |
81 cl->buf->temporary, cl->buf->in_file, | |
82 cl->buf->start, cl->buf->pos, | |
83 cl->buf->last - cl->buf->pos, | |
84 cl->buf->file_pos, | |
85 cl->buf->file_last - cl->buf->file_pos); | |
86 | |
87 #if 1 | |
88 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
89 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
90 "zero size buf in writer " | |
91 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
92 cl->buf->temporary, | |
93 cl->buf->recycled, | |
94 cl->buf->in_file, | |
95 cl->buf->start, | |
96 cl->buf->pos, | |
97 cl->buf->last, | |
98 cl->buf->file, | |
99 cl->buf->file_pos, | |
100 cl->buf->file_last); | |
101 | |
102 ngx_debug_point(); | |
103 return NGX_ERROR; | |
104 } | |
105 #endif | |
106 | |
107 size += ngx_buf_size(cl->buf); | |
108 | |
109 if (cl->buf->flush || cl->buf->recycled) { | |
110 flush = 1; | |
111 } | |
112 | |
113 if (cl->buf->last_buf) { | |
114 last = 1; | |
115 } | |
116 } | |
117 | |
118 /* add the new chain to the existent one */ | |
119 | |
120 for (ln = in; ln; ln = ln->next) { | |
121 cl = ngx_alloc_chain_link(r->pool); | |
122 if (cl == NULL) { | |
123 return NGX_ERROR; | |
124 } | |
125 | |
126 cl->buf = ln->buf; | |
127 *ll = cl; | |
128 ll = &cl->next; | |
129 | |
130 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0, | |
131 "write new buf t:%d f:%d %p, pos %p, size: %z " | |
132 "file: %O, size: %z", | |
133 cl->buf->temporary, cl->buf->in_file, | |
134 cl->buf->start, cl->buf->pos, | |
135 cl->buf->last - cl->buf->pos, | |
136 cl->buf->file_pos, | |
137 cl->buf->file_last - cl->buf->file_pos); | |
138 | |
139 #if 1 | |
140 if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { | |
141 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
142 "zero size buf in writer " | |
143 "t:%d r:%d f:%d %p %p-%p %p %O-%O", | |
144 cl->buf->temporary, | |
145 cl->buf->recycled, | |
146 cl->buf->in_file, | |
147 cl->buf->start, | |
148 cl->buf->pos, | |
149 cl->buf->last, | |
150 cl->buf->file, | |
151 cl->buf->file_pos, | |
152 cl->buf->file_last); | |
153 | |
154 ngx_debug_point(); | |
155 return NGX_ERROR; | |
156 } | |
157 #endif | |
158 | |
159 size += ngx_buf_size(cl->buf); | |
160 | |
161 if (cl->buf->flush || cl->buf->recycled) { | |
162 flush = 1; | |
163 } | |
164 | |
165 if (cl->buf->last_buf) { | |
166 last = 1; | |
167 } | |
168 } | |
169 | |
170 *ll = NULL; | |
171 | |
172 c = r->connection; | |
173 | |
174 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
175 "http write filter: l:%d f:%d s:%O", last, flush, size); | |
176 | |
177 clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, | |
178 ngx_http_core_module); | |
179 | |
180 /* | |
181 * avoid the output if there is no last buf, no flush point, | |
182 * there are the incoming bufs and the size of all bufs | |
183 * is smaller than "postpone_output" directive | |
184 */ | |
185 | |
186 if (!last && !flush && in && size < (off_t) clcf->postpone_output) { | |
187 return NGX_OK; | |
188 } | |
189 | |
190 if (c->write->delayed) { | |
191 return NGX_AGAIN; | |
192 } | |
193 | |
194 if (size == 0 && !c->buffered) { | |
195 if (last) { | |
196 return NGX_OK; | |
197 } | |
198 | |
199 if (flush) { | |
200 do { | |
201 ctx->out = ctx->out->next; | |
202 } | |
203 while (ctx->out); | |
204 | |
205 return NGX_OK; | |
206 } | |
207 | |
208 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
209 "the http output chain is empty"); | |
210 | |
211 ngx_debug_point(); | |
212 | |
213 return NGX_ERROR; | |
214 } | |
215 | |
216 sent = c->sent; | |
217 | |
218 chain = c->send_chain(c, ctx->out, clcf->limit_rate); | |
219 | |
220 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
221 "http write filter %p", chain); | |
222 | |
223 if (clcf->limit_rate) { | |
224 sent = c->sent - sent; | |
225 c->write->delayed = 1; | |
226 ngx_add_timer(r->connection->write, | |
227 (ngx_msec_t) (sent * 1000 / clcf->limit_rate)); | |
228 } | |
229 | |
230 if (chain == NGX_CHAIN_ERROR) { | |
231 return NGX_ERROR; | |
232 } | |
233 | |
234 ctx->out = chain; | |
235 | |
236 if (chain || (last && c->buffered)) { | |
237 return NGX_AGAIN; | |
238 } | |
239 | |
240 return NGX_OK; | |
241 } | |
242 | |
243 | |
244 static ngx_int_t | |
245 ngx_http_write_filter_init(ngx_cycle_t *cycle) | |
246 { | |
247 ngx_http_top_body_filter = ngx_http_write_filter; | |
248 | |
249 return NGX_OK; | |
250 } |