Mercurial > hg > nginx
annotate src/http/modules/ngx_http_chunked_filter_module.c @ 6470:62d950bc0f15
Updated OpenSSL used for win32 builds.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 29 Mar 2016 09:54:11 +0300 |
parents | b1858fc47e3b |
children | f01ab2dbcfdc |
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 | |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
65 || r->headers_out.status < NGX_HTTP_OK |
3331
e0bc43a52382
backout r3325: postpone filter is a body only filter
Igor Sysoev <igor@sysoev.ru>
parents:
3324
diff
changeset
|
66 || r != r->main |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
67 || r->method == NGX_HTTP_HEAD) |
615 | 68 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
69 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
|
70 } |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
71 |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
72 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
|
73 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
|
74 r->keepalive = 0; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 } else { |
3484 | 77 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
78 | |
79 if (clcf->chunked_transfer_encoding) { | |
80 r->chunked = 1; | |
81 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
82 ctx = ngx_pcalloc(r->pool, |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
83 sizeof(ngx_http_chunked_filter_ctx_t)); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
84 if (ctx == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
85 return NGX_ERROR; |
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 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
88 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
|
89 |
3484 | 90 } else { |
91 r->keepalive = 0; | |
92 } | |
99
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 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
96 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
|
97 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
501 | 100 static ngx_int_t |
101 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
|
102 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
103 u_char *chunk; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
104 off_t size; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
105 ngx_int_t rc; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
106 ngx_buf_t *b; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
107 ngx_chain_t *out, *cl, *tl, **ll; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
108 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
|
109 |
483 | 110 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
|
111 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
|
112 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
114 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
|
115 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
116 out = NULL; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
117 ll = &out; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 size = 0; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
120 cl = in; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 for ( ;; ) { |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
123 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
|
124 "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
|
125 |
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
|
126 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
|
127 |
667 | 128 if (cl->buf->flush |
129 || cl->buf->sync | |
130 || ngx_buf_in_memory(cl->buf) | |
131 || cl->buf->in_file) | |
132 { | |
501 | 133 tl = ngx_alloc_chain_link(r->pool); |
134 if (tl == NULL) { | |
461 | 135 return NGX_ERROR; |
136 } | |
137 | |
452 | 138 tl->buf = cl->buf; |
139 *ll = tl; | |
140 ll = &tl->next; | |
141 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
143 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
|
144 break; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
147 cl = cl->next; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
150 if (size) { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
151 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
|
152 if (tl == NULL) { |
455 | 153 return NGX_ERROR; |
154 } | |
155 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
156 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
157 chunk = b->start; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
158 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
159 if (chunk == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
160 /* the "0000000000000000" is 64-bit hexadecimal string */ |
501 | 161 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
162 chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
163 if (chunk == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
164 return NGX_ERROR; |
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 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
167 b->start = chunk; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
168 b->end = chunk + sizeof("0000000000000000" CRLF) - 1; |
455 | 169 } |
170 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
171 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
|
172 b->memory = 0; |
455 | 173 b->temporary = 1; |
174 b->pos = chunk; | |
473 | 175 b->last = ngx_sprintf(chunk, "%xO" CRLF, size); |
455 | 176 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
177 tl->next = out; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
178 out = tl; |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
179 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
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
|
181 if (cl->buf->last_buf) { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
182 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
|
183 if (tl == NULL) { |
461 | 184 return NGX_ERROR; |
185 } | |
4128 | 186 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
187 b = tl->buf; |
461 | 188 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 |
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
|
196 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
|
197 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
198 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
199 |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
200 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
|
201 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
|
202 } |
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
203 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
204 } else if (size > 0) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
205 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
|
206 if (tl == NULL) { |
461 | 207 return NGX_ERROR; |
208 } | |
209 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
210 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
211 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 b->last = b->pos + 2; |
4113
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 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
219 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
220 } else { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
221 *ll = NULL; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
224 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
|
225 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4113
diff
changeset
|
226 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
|
227 (ngx_buf_tag_t) &ngx_http_chunked_filter_module); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
228 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
229 return rc; |
99
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 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 |
501 | 233 static ngx_int_t |
681 | 234 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
|
235 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
236 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
|
237 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
|
238 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
239 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
|
240 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
|
241 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 } |