Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_chunked_filter_module.c @ 4628:f675474435e0
Reverted previous attempt to fix complation warning introduced in
r4624 and actually fixed it.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 14 May 2012 15:52:37 +0000 |
parents | d620f497c50f |
children | 7fa7e60a7f66 |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
13 typedef struct { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
14 ngx_chain_t *free; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
15 ngx_chain_t *busy; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
16 } ngx_http_chunked_filter_ctx_t; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
17 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
18 |
681 | 19 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
|
20 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 static ngx_http_module_t ngx_http_chunked_filter_module_ctx = { |
509 | 23 NULL, /* preconfiguration */ |
681 | 24 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
|
25 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 NULL, /* create main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 NULL, /* init main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 NULL, /* create location configuration */ |
629 | 33 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
|
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 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 ngx_module_t ngx_http_chunked_filter_module = { |
509 | 38 NGX_MODULE_V1, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 &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
|
40 NULL, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 NGX_HTTP_MODULE, /* module type */ |
541 | 42 NULL, /* init master */ |
681 | 43 NULL, /* init module */ |
541 | 44 NULL, /* init process */ |
45 NULL, /* init thread */ | |
46 NULL, /* exit thread */ | |
47 NULL, /* exit process */ | |
48 NULL, /* exit master */ | |
49 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
|
50 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 |
155
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_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
|
54 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
|
55 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 |
501 | 57 static ngx_int_t |
58 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
|
59 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
60 ngx_http_core_loc_conf_t *clcf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
61 ngx_http_chunked_filter_ctx_t *ctx; |
3484 | 62 |
615 | 63 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED |
64 || 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
|
65 || r != r->main |
2270
e274c8e5d49c
do not set "Transfer-Encoding: chunked" for HEAD requests
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
66 || (r->method & NGX_HTTP_HEAD)) |
615 | 67 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
68 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
|
69 } |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
70 |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
71 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
|
72 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
|
73 r->keepalive = 0; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 } else { |
3484 | 76 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
77 | |
78 if (clcf->chunked_transfer_encoding) { | |
79 r->chunked = 1; | |
80 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
81 ctx = ngx_pcalloc(r->pool, |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
82 sizeof(ngx_http_chunked_filter_ctx_t)); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
83 if (ctx == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
84 return NGX_ERROR; |
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 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
87 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
|
88 |
3484 | 89 } else { |
90 r->keepalive = 0; | |
91 } | |
99
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 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
95 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
|
96 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 |
501 | 99 static ngx_int_t |
100 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
|
101 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
102 u_char *chunk; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
103 off_t size; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
104 ngx_int_t rc; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
105 ngx_buf_t *b; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
106 ngx_chain_t *out, *cl, *tl, **ll; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
107 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
|
108 |
483 | 109 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
|
110 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
|
111 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
113 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
|
114 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
115 out = NULL; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
116 ll = &out; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 size = 0; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
119 cl = in; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 for ( ;; ) { |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
122 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
|
123 "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
|
124 |
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
|
125 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
|
126 |
667 | 127 if (cl->buf->flush |
128 || cl->buf->sync | |
129 || ngx_buf_in_memory(cl->buf) | |
130 || cl->buf->in_file) | |
131 { | |
501 | 132 tl = ngx_alloc_chain_link(r->pool); |
133 if (tl == NULL) { | |
461 | 134 return NGX_ERROR; |
135 } | |
136 | |
452 | 137 tl->buf = cl->buf; |
138 *ll = tl; | |
139 ll = &tl->next; | |
140 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
142 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
|
143 break; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
146 cl = cl->next; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
149 if (size) { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
150 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
|
151 if (tl == NULL) { |
455 | 152 return NGX_ERROR; |
153 } | |
154 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
155 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
156 chunk = b->start; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
157 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
158 if (chunk == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
159 /* the "0000000000000000" is 64-bit hexadecimal string */ |
501 | 160 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
161 chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
162 if (chunk == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
163 return NGX_ERROR; |
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 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
166 b->start = chunk; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
167 b->end = chunk + sizeof("0000000000000000" CRLF) - 1; |
455 | 168 } |
169 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
170 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
|
171 b->memory = 0; |
455 | 172 b->temporary = 1; |
173 b->pos = chunk; | |
473 | 174 b->last = ngx_sprintf(chunk, "%xO" CRLF, size); |
455 | 175 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
176 tl->next = out; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
177 out = tl; |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
178 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 |
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
|
180 if (cl->buf->last_buf) { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
181 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
|
182 if (tl == NULL) { |
461 | 183 return NGX_ERROR; |
184 } | |
4128 | 185 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
186 b = tl->buf; |
461 | 187 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 |
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
|
195 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
|
196 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
197 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
198 |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
199 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
|
200 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
|
201 } |
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
202 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
203 } else if (size > 0) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
204 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
|
205 if (tl == NULL) { |
461 | 206 return NGX_ERROR; |
207 } | |
208 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
209 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
210 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 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
|
215 b->last = b->pos + 2; |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
216 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
217 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
218 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
219 } else { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
220 *ll = NULL; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
223 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
|
224 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4113
diff
changeset
|
225 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
|
226 (ngx_buf_tag_t) &ngx_http_chunked_filter_module); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
227 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
228 return rc; |
99
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 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 |
501 | 232 static ngx_int_t |
681 | 233 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
|
234 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
235 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
|
236 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
|
237 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
238 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
|
239 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
|
240 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 } |