annotate src/http/modules/ngx_http_chunked_filter_module.c @ 4207:4fc91bae6f83

Better recheck of dead upstream servers. Previously nginx used to mark backend again as live as soon as fail_timeout passes (10s by default) since last failure. On the other hand, detecting dead backend takes up to 60s (proxy_connect_timeout) in typical situation "backend is down and doesn't respond to any packets". This resulted in suboptimal behaviour in the above situation (up to 23% of requests were directed to dead backend with default settings). More detailed description of the problem may be found here (in Russian): http://mailman.nginx.org/pipermail/nginx-ru/2011-August/042172.html Fix is to only allow one request after fail_timeout passes, and mark backend as "live" only if this request succeeds. Note that with new code backend will not be marked "live" unless "check" request is completed, and this may take a while in some specific workloads (e.g. streaming). This is believed to be acceptable.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 12 Oct 2011 14:22:48 +0000
parents 4b0b0e77dc3d
children d620f497c50f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
4 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 356
diff changeset
5
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
12 typedef struct {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
13 ngx_chain_t *free;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
14 ngx_chain_t *busy;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
15 } ngx_http_chunked_filter_ctx_t;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
16
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
17
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
18 static ngx_int_t ngx_http_chunked_filter_init(ngx_conf_t *cf);
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 static ngx_http_module_t ngx_http_chunked_filter_module_ctx = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
22 NULL, /* preconfiguration */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
23 ngx_http_chunked_filter_init, /* postconfiguration */
177
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
24
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 NULL, /* create main configuration */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 NULL, /* init main configuration */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 NULL, /* create server configuration */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 NULL, /* merge server configuration */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 NULL, /* create location configuration */
629
65bf042c0b4f nginx-0.3.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 615
diff changeset
32 NULL /* merge location configuration */
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 };
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 ngx_module_t ngx_http_chunked_filter_module = {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
37 NGX_MODULE_V1,
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 &ngx_http_chunked_filter_module_ctx, /* module context */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 NULL, /* module directives */
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 NGX_HTTP_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
41 NULL, /* init master */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
42 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
43 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
44 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
45 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
46 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
47 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
48 NGX_MODULE_V1_PADDING
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 };
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
52 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
53 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
56 static ngx_int_t
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
57 ngx_http_chunked_header_filter(ngx_http_request_t *r)
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 {
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
59 ngx_http_core_loc_conf_t *clcf;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
60 ngx_http_chunked_filter_ctx_t *ctx;
3484
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
61
615
5ef026a2ac74 nginx-0.3.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
62 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED
5ef026a2ac74 nginx-0.3.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
63 || r->headers_out.status == NGX_HTTP_NO_CONTENT
3331
e0bc43a52382 backout r3325: postpone filter is a body only filter
Igor Sysoev <igor@sysoev.ru>
parents: 3324
diff changeset
64 || r != r->main
2270
e274c8e5d49c do not set "Transfer-Encoding: chunked" for HEAD requests
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
65 || (r->method & NGX_HTTP_HEAD))
615
5ef026a2ac74 nginx-0.3.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
66 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
67 return ngx_http_next_header_filter(r);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
68 }
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
69
153
c71aeb75c071 nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents: 135
diff changeset
70 if (r->headers_out.content_length_n == -1) {
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 if (r->http_version < NGX_HTTP_VERSION_11) {
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 r->keepalive = 0;
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 } else {
3484
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
75 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
76
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
77 if (clcf->chunked_transfer_encoding) {
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
78 r->chunked = 1;
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
79
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
80 ctx = ngx_pcalloc(r->pool,
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
81 sizeof(ngx_http_chunked_filter_ctx_t));
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
82 if (ctx == NULL) {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
83 return NGX_ERROR;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
84 }
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
85
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
86 ngx_http_set_ctx(r, ctx, ngx_http_chunked_filter_module);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
87
3484
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
88 } else {
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
89 r->keepalive = 0;
81457372d938 chunked_transfer_encoding
Igor Sysoev <igor@sysoev.ru>
parents: 3411
diff changeset
90 }
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
94 return ngx_http_next_header_filter(r);
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
98 static ngx_int_t
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
99 ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 {
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
101 u_char *chunk;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
102 off_t size;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
103 ngx_int_t rc;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
104 ngx_buf_t *b;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
105 ngx_chain_t *out, *cl, *tl, **ll;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
106 ngx_http_chunked_filter_ctx_t *ctx;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 473
diff changeset
108 if (in == NULL || !r->chunked || r->header_only) {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
109 return ngx_http_next_body_filter(r, in);
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
112 ctx = ngx_http_get_module_ctx(r, ngx_http_chunked_filter_module);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
114 out = NULL;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
115 ll = &out;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 size = 0;
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
118 cl = in;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 for ( ;; ) {
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
121 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
122 "http chunk: %d", ngx_buf_size(cl->buf));
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
123
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
124 size += ngx_buf_size(cl->buf);
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
126 if (cl->buf->flush
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
127 || cl->buf->sync
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
128 || ngx_buf_in_memory(cl->buf)
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
129 || cl->buf->in_file)
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
130 {
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
131 tl = ngx_alloc_chain_link(r->pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
132 if (tl == NULL) {
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
133 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
134 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
135
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
136 tl->buf = cl->buf;
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
137 *ll = tl;
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
138 ll = &tl->next;
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
139 }
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
141 if (cl->next == NULL) {
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 break;
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
145 cl = cl->next;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
148 if (size) {
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
149 tl = ngx_chain_get_free_buf(r->pool, &ctx->free);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
150 if (tl == NULL) {
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
151 return NGX_ERROR;
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
152 }
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
153
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
154 b = tl->buf;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
155 chunk = b->start;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
156
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
157 if (chunk == NULL) {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
158 /* the "0000000000000000" is 64-bit hexadecimal string */
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
159
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
160 chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
161 if (chunk == NULL) {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
162 return NGX_ERROR;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
163 }
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
164
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
165 b->start = chunk;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
166 b->end = chunk + sizeof("0000000000000000" CRLF) - 1;
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
167 }
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
168
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
169 b->tag = (ngx_buf_tag_t) &ngx_http_chunked_filter_module;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
170 b->memory = 0;
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
171 b->temporary = 1;
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
172 b->pos = chunk;
473
8e8f3af115b5 nginx-0.1.11-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 461
diff changeset
173 b->last = ngx_sprintf(chunk, "%xO" CRLF, size);
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
174
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
175 tl->next = out;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
176 out = tl;
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
177 }
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
179 if (cl->buf->last_buf) {
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
180 tl = ngx_chain_get_free_buf(r->pool, &ctx->free);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
181 if (tl == NULL) {
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
182 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
183 }
4128
4b0b0e77dc3d Trailing space fix.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4114
diff changeset
184
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
185 b = tl->buf;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
186
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
187 b->tag = (ngx_buf_tag_t) &ngx_http_chunked_filter_module;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
188 b->temporary = 0;
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
189 b->memory = 1;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
190 b->last_buf = 1;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
191 b->pos = (u_char *) CRLF "0" CRLF CRLF;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
192 b->last = b->pos + 7;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
194 cl->buf->last_buf = 0;
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
195
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
196 *ll = tl;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
197
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
198 if (size == 0) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
199 b->pos += 2;
336
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
200 }
ca9a7f8c86da nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
201
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
202 } else if (size > 0) {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
203 tl = ngx_chain_get_free_buf(r->pool, &ctx->free);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
204 if (tl == NULL) {
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
205 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
206 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
207
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
208 b = tl->buf;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
209
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
210 b->tag = (ngx_buf_tag_t) &ngx_http_chunked_filter_module;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
211 b->temporary = 0;
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
212 b->memory = 1;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
213 b->pos = (u_char *) CRLF;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 337
diff changeset
214 b->last = b->pos + 2;
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
215
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
216 *ll = tl;
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
217
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
218 } else {
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
219 *ll = NULL;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
222 rc = ngx_http_next_body_filter(r, out);
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4113
diff changeset
224 ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &out,
4113
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
225 (ngx_buf_tag_t) &ngx_http_chunked_filter_module);
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
226
a28ba1cdec27 Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3484
diff changeset
227 return rc;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 }
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
231 static ngx_int_t
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 667
diff changeset
232 ngx_http_chunked_filter_init(ngx_conf_t *cf)
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
234 ngx_http_next_header_filter = ngx_http_top_header_filter;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 ngx_http_top_header_filter = ngx_http_chunked_header_filter;
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
237 ngx_http_next_body_filter = ngx_http_top_body_filter;
99
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 ngx_http_top_body_filter = ngx_http_chunked_body_filter;
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 return NGX_OK;
a059e1aa65d4 nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 }