Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_chunked_filter_module.c @ 7785:29354c6fc5f2 quic
TLS Key Update in QUIC.
Old keys retention is yet to be implemented.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 06 Apr 2020 14:54:08 +0300 |
parents | 46e3542d51b3 |
children | ef83990f0e25 |
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); |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
20 static ngx_chain_t *ngx_http_chunked_create_trailers(ngx_http_request_t *r, |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
21 ngx_http_chunked_filter_ctx_t *ctx, size_t size); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 static ngx_http_module_t ngx_http_chunked_filter_module_ctx = { |
509 | 25 NULL, /* preconfiguration */ |
681 | 26 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
|
27 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 NULL, /* create main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 NULL, /* init main 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 server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 NULL, /* merge server configuration */ |
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 NULL, /* create location configuration */ |
629 | 35 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
|
36 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 ngx_module_t ngx_http_chunked_filter_module = { |
509 | 40 NGX_MODULE_V1, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 &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
|
42 NULL, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 NGX_HTTP_MODULE, /* module type */ |
541 | 44 NULL, /* init master */ |
681 | 45 NULL, /* init module */ |
541 | 46 NULL, /* init process */ |
47 NULL, /* init thread */ | |
48 NULL, /* exit thread */ | |
49 NULL, /* exit process */ | |
50 NULL, /* exit master */ | |
51 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
|
52 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
55 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
|
56 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
|
57 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
501 | 59 static ngx_int_t |
60 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
|
61 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
62 ngx_http_core_loc_conf_t *clcf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
63 ngx_http_chunked_filter_ctx_t *ctx; |
3484 | 64 |
615 | 65 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED |
66 || 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
|
67 || 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
|
68 || r != r->main |
6306
b1858fc47e3b
Style: unified request method checks.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
69 || r->method == NGX_HTTP_HEAD) |
615 | 70 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
71 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
|
72 } |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
73 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
74 if (r->headers_out.content_length_n == -1 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
75 || r->expect_trailers) |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
76 { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
77 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
79 if (r->http_version >= NGX_HTTP_VERSION_11 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
80 && clcf->chunked_transfer_encoding) |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
81 { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
82 if (r->expect_trailers) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
83 ngx_http_clear_content_length(r); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
84 } |
3484 | 85 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
86 r->chunked = 1; |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
87 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
88 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_chunked_filter_ctx_t)); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
89 if (ctx == NULL) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
90 return NGX_ERROR; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
91 } |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
92 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
93 ngx_http_set_ctx(r, ctx, ngx_http_chunked_filter_module); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
94 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
95 } else if (r->headers_out.content_length_n == -1) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
96 r->keepalive = 0; |
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 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
100 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
|
101 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
501 | 104 static ngx_int_t |
105 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
|
106 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
107 u_char *chunk; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
108 off_t size; |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
109 size_t n; |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
110 ngx_int_t rc; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
111 ngx_buf_t *b; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
112 ngx_chain_t *out, *cl, *tl, **ll; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
113 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
|
114 |
483 | 115 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
|
116 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
|
117 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
119 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
|
120 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
121 out = NULL; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
122 ll = &out; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 size = 0; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
125 cl = in; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 for ( ;; ) { |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
128 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6480 | 129 "http chunk: %O", 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
|
130 |
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
|
131 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
|
132 |
667 | 133 if (cl->buf->flush |
134 || cl->buf->sync | |
135 || ngx_buf_in_memory(cl->buf) | |
136 || cl->buf->in_file) | |
137 { | |
501 | 138 tl = ngx_alloc_chain_link(r->pool); |
139 if (tl == NULL) { | |
461 | 140 return NGX_ERROR; |
141 } | |
142 | |
452 | 143 tl->buf = cl->buf; |
144 *ll = tl; | |
145 ll = &tl->next; | |
146 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
148 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
|
149 break; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
152 cl = cl->next; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
155 if (size) { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
156 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
|
157 if (tl == NULL) { |
455 | 158 return NGX_ERROR; |
159 } | |
160 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
161 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
162 chunk = b->start; |
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 if (chunk == NULL) { |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
165 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
166 #if (NGX_HTTP_V3) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
167 if (r->http_version == NGX_HTTP_VERSION_30) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
168 n = NGX_HTTP_V3_VARLEN_INT_LEN * 2; |
501 | 169 |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
170 } else |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
171 #endif |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
172 { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
173 /* the "0000000000000000" is 64-bit hexadecimal string */ |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
174 n = sizeof("0000000000000000" CRLF) - 1; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
175 } |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
176 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
177 chunk = ngx_palloc(r->pool, n); |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
178 if (chunk == NULL) { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
179 return NGX_ERROR; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
180 } |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
181 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
182 b->start = chunk; |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
183 b->end = chunk + n; |
455 | 184 } |
185 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
186 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
|
187 b->memory = 0; |
455 | 188 b->temporary = 1; |
189 b->pos = chunk; | |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
190 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
191 #if (NGX_HTTP_V3) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
192 if (r->http_version == NGX_HTTP_VERSION_30) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
193 b->last = (u_char *) ngx_http_v3_encode_varlen_int(chunk, |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
194 NGX_HTTP_V3_FRAME_DATA); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
195 b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, size); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
196 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
197 } else |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
198 #endif |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
199 { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
200 b->last = ngx_sprintf(chunk, "%xO" CRLF, size); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
201 } |
455 | 202 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
203 tl->next = out; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
204 out = tl; |
336
ca9a7f8c86da
nginx-0.0.3-2004-05-18-19:29:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
205 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 |
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
|
207 if (cl->buf->last_buf) { |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
208 tl = ngx_http_chunked_create_trailers(r, ctx, size); |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
209 if (tl == NULL) { |
461 | 210 return NGX_ERROR; |
211 } | |
4128 | 212 |
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 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
|
214 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
215 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
216 |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
217 } else if (size > 0 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
218 #if (NGX_HTTP_V3) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
219 && r->http_version != NGX_HTTP_VERSION_30 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
220 #endif |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
221 ) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
222 { |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
223 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
|
224 if (tl == NULL) { |
461 | 225 return NGX_ERROR; |
226 } | |
227 | |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
228 b = tl->buf; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
229 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 b->last = b->pos + 2; |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
235 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
236 *ll = tl; |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
237 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
238 } else { |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
239 *ll = NULL; |
99
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 |
4113
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
242 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
|
243 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4113
diff
changeset
|
244 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
|
245 (ngx_buf_tag_t) &ngx_http_chunked_filter_module); |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
246 |
a28ba1cdec27
Buffers reuse in chunked filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3484
diff
changeset
|
247 return rc; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
248 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
251 static ngx_chain_t * |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
252 ngx_http_chunked_create_trailers(ngx_http_request_t *r, |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
253 ngx_http_chunked_filter_ctx_t *ctx, size_t size) |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
254 { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
255 size_t len; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
256 ngx_buf_t *b; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
257 ngx_uint_t i; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
258 ngx_chain_t *cl; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
259 ngx_list_part_t *part; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
260 ngx_table_elt_t *header; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
261 |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
262 #if (NGX_HTTP_V3) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
263 if (r->http_version == NGX_HTTP_VERSION_30) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
264 return ngx_http_v3_create_trailers(r); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
265 } |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
266 #endif |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
267 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
268 len = 0; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
269 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
270 part = &r->headers_out.trailers.part; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
271 header = part->elts; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
272 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
273 for (i = 0; /* void */; i++) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
274 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
275 if (i >= part->nelts) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
276 if (part->next == NULL) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
277 break; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
278 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
279 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
280 part = part->next; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
281 header = part->elts; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
282 i = 0; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
283 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
284 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
285 if (header[i].hash == 0) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
286 continue; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
287 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
288 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
289 len += header[i].key.len + sizeof(": ") - 1 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
290 + header[i].value.len + sizeof(CRLF) - 1; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
291 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
292 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
293 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
294 if (cl == NULL) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
295 return NULL; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
296 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
297 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
298 b = cl->buf; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
299 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
300 b->tag = (ngx_buf_tag_t) &ngx_http_chunked_filter_module; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
301 b->temporary = 0; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
302 b->memory = 1; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
303 b->last_buf = 1; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
304 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
305 if (len == 0) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
306 b->pos = (u_char *) CRLF "0" CRLF CRLF; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
307 b->last = b->pos + sizeof(CRLF "0" CRLF CRLF) - 1; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
308 return cl; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
309 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
310 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
311 len += sizeof(CRLF "0" CRLF CRLF) - 1; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
312 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
313 b->pos = ngx_palloc(r->pool, len); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
314 if (b->pos == NULL) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
315 return NULL; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
316 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
317 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
318 b->last = b->pos; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
319 |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
320 if (size > 0) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
321 *b->last++ = CR; *b->last++ = LF; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
322 } |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7034
diff
changeset
|
323 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
324 *b->last++ = '0'; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
325 *b->last++ = CR; *b->last++ = LF; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
326 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
327 part = &r->headers_out.trailers.part; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
328 header = part->elts; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
329 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
330 for (i = 0; /* void */; i++) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
331 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
332 if (i >= part->nelts) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
333 if (part->next == NULL) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
334 break; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
335 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
336 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
337 part = part->next; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
338 header = part->elts; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
339 i = 0; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
340 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
341 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
342 if (header[i].hash == 0) { |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
343 continue; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
344 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
345 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
346 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
347 "http trailer: \"%V: %V\"", |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
348 &header[i].key, &header[i].value); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
349 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
350 b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
351 *b->last++ = ':'; *b->last++ = ' '; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
352 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
353 b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
354 *b->last++ = CR; *b->last++ = LF; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
355 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
356 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
357 *b->last++ = CR; *b->last++ = LF; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
358 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
359 return cl; |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
360 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
361 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6480
diff
changeset
|
362 |
501 | 363 static ngx_int_t |
681 | 364 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
|
365 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
366 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
|
367 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
|
368 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
369 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
|
370 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
|
371 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
372 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
373 } |