Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_chunked_filter_module.c @ 4310:13f108b9f3cf
Fixed build without atomic operations.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 23 Nov 2011 14:07:06 +0000 |
parents | 4b0b0e77dc3d |
children | d620f497c50f |
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 | 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 | 22 NULL, /* preconfiguration */ |
681 | 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 | 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 | 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 | 41 NULL, /* init master */ |
681 | 42 NULL, /* init module */ |
541 | 43 NULL, /* init process */ |
44 NULL, /* init thread */ | |
45 NULL, /* exit thread */ | |
46 NULL, /* exit process */ | |
47 NULL, /* exit master */ | |
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 | 56 static ngx_int_t |
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 | 61 |
615 | 62 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED |
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 | 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 | 75 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
76 | |
77 if (clcf->chunked_transfer_encoding) { | |
78 r->chunked = 1; | |
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 | 88 } else { |
89 r->keepalive = 0; | |
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 | 98 static ngx_int_t |
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 | 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 | 126 if (cl->buf->flush |
127 || cl->buf->sync | |
128 || ngx_buf_in_memory(cl->buf) | |
129 || cl->buf->in_file) | |
130 { | |
501 | 131 tl = ngx_alloc_chain_link(r->pool); |
132 if (tl == NULL) { | |
461 | 133 return NGX_ERROR; |
134 } | |
135 | |
452 | 136 tl->buf = cl->buf; |
137 *ll = tl; | |
138 ll = &tl->next; | |
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 | 151 return NGX_ERROR; |
152 } | |
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 | 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 | 167 } |
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 | 171 b->temporary = 1; |
172 b->pos = chunk; | |
473 | 173 b->last = ngx_sprintf(chunk, "%xO" CRLF, size); |
455 | 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 | 182 return NGX_ERROR; |
183 } | |
4128 | 184 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
185 b = tl->buf; |
461 | 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 | 205 return NGX_ERROR; |
206 } | |
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 | 231 static ngx_int_t |
681 | 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 } |