Mercurial > hg > nginx
annotate src/http/ngx_http_request_body.c @ 8548:9ffef6054abf quic
HTTP/3: fixed handling request body eof.
While for HTTP/1 unexpected eof always means an error, for HTTP/3 an eof right
after a DATA frame end means the end of the request body. For this reason,
since adding HTTP/3 support, eof no longer produced an error right after recv()
but was passed to filters which would make a decision. This decision was made
in ngx_http_parse_chunked() and ngx_http_v3_parse_request_body() based on the
b->last_buf flag.
Now that since 0f7f1a509113 (1.19.2) rb->chunked->length is a lower threshold
for the expected number of bytes, it can be set to zero to indicate that more
bytes may or may not follow. Now it's possible to move the check for eof from
parser functions to ngx_http_request_body_chunked_filter() and clean up the
parsing code.
Also, in the default branch, in case of eof, the following three things
happened, which were replaced with returning NGX_ERROR while implementing
HTTP/3:
- "client prematurely closed connection" message was logged
- c->error flag was set
- NGX_HTTP_BAD_REQUEST was returned
The change brings back this behavior for HTTP/1 as well as HTTP/3.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 16 Sep 2020 18:59:25 +0100 |
parents | eaea7dac3292 |
children | 5a794d2452ef |
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:
396
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:
396
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:
396
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:
396
diff
changeset
|
6 |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
8 #include <ngx_config.h> |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
9 #include <ngx_core.h> |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
10 #include <ngx_http.h> |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
509 | 13 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); |
14 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); | |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
15 static ngx_int_t ngx_http_copy_pipelined_header(ngx_http_request_t *r, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
16 ngx_buf_t *buf); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
17 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r); |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
18 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
19 static ngx_int_t ngx_http_discard_request_body_filter(ngx_http_request_t *r, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
20 ngx_buf_t *b); |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
21 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r); |
633 | 22 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
23 static ngx_int_t ngx_http_request_body_filter(ngx_http_request_t *r, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
24 ngx_chain_t *in); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
25 static ngx_int_t ngx_http_request_body_length_filter(ngx_http_request_t *r, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
26 ngx_chain_t *in); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
27 static ngx_int_t ngx_http_request_body_chunked_filter(ngx_http_request_t *r, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
28 ngx_chain_t *in); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
29 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
30 |
501 | 31 ngx_int_t |
32 ngx_http_read_client_request_body(ngx_http_request_t *r, | |
33 ngx_http_client_body_handler_pt post_handler) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
34 { |
663 | 35 size_t preread; |
36 ssize_t size; | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
37 ngx_int_t rc; |
5025
43cb2c9799c1
Request body: fixed client_body_in_file_only.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4937
diff
changeset
|
38 ngx_buf_t *b; |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
39 ngx_chain_t out; |
479 | 40 ngx_http_request_body_t *rb; |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
41 ngx_http_core_loc_conf_t *clcf; |
297
ee394e997c77
nginx-0.0.3-2004-03-29-21:43:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
296
diff
changeset
|
42 |
3049 | 43 r->main->count++; |
44 | |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
45 if (r != r->main || r->request_body || r->discard_body) { |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
46 r->request_body_no_buffering = 0; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
47 post_handler(r); |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
48 return NGX_OK; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
49 } |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
50 |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
51 if (ngx_http_test_expect(r) != NGX_OK) { |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
52 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
53 goto done; |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
54 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
55 |
501 | 56 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
57 if (rb == NULL) { | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
58 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
59 goto done; |
479 | 60 } |
61 | |
62 /* | |
63 * set by ngx_pcalloc(): | |
64 * | |
65 * rb->bufs = NULL; | |
66 * rb->buf = NULL; | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
67 * rb->free = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
68 * rb->busy = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
69 * rb->chunked = NULL; |
479 | 70 */ |
71 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
72 rb->rest = -1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
73 rb->post_handler = post_handler; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
74 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
75 r->request_body = rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
76 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
77 if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
78 r->request_body_no_buffering = 0; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
79 post_handler(r); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
80 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
81 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
82 |
6989
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
83 #if (NGX_HTTP_V2) |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
84 if (r->stream) { |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
85 rc = ngx_http_v2_read_request_body(r); |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
86 goto done; |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
87 } |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
88 #endif |
2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6904
diff
changeset
|
89 |
633 | 90 preread = r->header_in->last - r->header_in->pos; |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
91 |
633 | 92 if (preread) { |
296
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
93 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
94 /* there is the pre-read part of the request body */ |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
95 |
633 | 96 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
97 "http client request body preread %uz", preread); | |
98 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
99 out.buf = r->header_in; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
100 out.next = NULL; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
102 rc = ngx_http_request_body_filter(r, &out); |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
104 if (rc != NGX_OK) { |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
105 goto done; |
479 | 106 } |
107 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
108 r->request_length += preread - (r->header_in->last - r->header_in->pos); |
299
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
109 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
110 if (!r->headers_in.chunked |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
111 && rb->rest > 0 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
112 && rb->rest <= (off_t) (r->header_in->end - r->header_in->last)) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
113 { |
633 | 114 /* the whole request body may be placed in r->header_in */ |
115 | |
5111
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
116 b = ngx_calloc_buf(r->pool); |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
117 if (b == NULL) { |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
118 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
119 goto done; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
120 } |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
121 |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
122 b->temporary = 1; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
123 b->start = r->header_in->pos; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
124 b->pos = r->header_in->pos; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
125 b->last = r->header_in->last; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
126 b->end = r->header_in->end; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
127 |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
128 rb->buf = b; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
129 |
633 | 130 r->read_event_handler = ngx_http_read_client_request_body_handler; |
4937
3b6594a2b79f
Request body: block write events while reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4936
diff
changeset
|
131 r->write_event_handler = ngx_http_request_empty_handler; |
633 | 132 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
133 rc = ngx_http_do_read_client_request_body(r); |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
134 goto done; |
633 | 135 } |
136 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
137 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
138 /* set rb->rest */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
139 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
140 if (ngx_http_request_body_filter(r, NULL) != NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
141 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
142 goto done; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
143 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
144 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
145 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
146 if (rb->rest == 0) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
147 /* the whole request body was pre-read */ |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
148 r->request_body_no_buffering = 0; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
149 post_handler(r); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
150 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 |
4936
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
153 if (rb->rest < 0) { |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
154 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
155 "negative request body rest"); |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
156 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
157 goto done; |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
158 } |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
159 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
160 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
161 |
633 | 162 size = clcf->client_body_buffer_size; |
163 size += size >> 2; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
164 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
165 /* TODO: honor r->request_body_in_single_buf */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
166 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
167 if (!r->headers_in.chunked && rb->rest < size) { |
663 | 168 size = (ssize_t) rb->rest; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
169 |
633 | 170 if (r->request_body_in_single_buf) { |
171 size += preread; | |
172 } | |
173 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
174 } else { |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
175 size = clcf->client_body_buffer_size; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
176 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
177 |
501 | 178 rb->buf = ngx_create_temp_buf(r->pool, size); |
179 if (rb->buf == NULL) { | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
180 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
181 goto done; |
479 | 182 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
183 |
509 | 184 r->read_event_handler = ngx_http_read_client_request_body_handler; |
4937
3b6594a2b79f
Request body: block write events while reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4936
diff
changeset
|
185 r->write_event_handler = ngx_http_request_empty_handler; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
187 rc = ngx_http_do_read_client_request_body(r); |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
188 |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
189 done: |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
190 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
191 if (r->request_body_no_buffering |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
192 && (rc == NGX_OK || rc == NGX_AGAIN)) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
193 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
194 if (rc == NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
195 r->request_body_no_buffering = 0; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
196 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
197 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
198 /* rc == NGX_AGAIN */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
199 r->reading_body = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
200 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
201 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
202 r->read_event_handler = ngx_http_block_reading; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
203 post_handler(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
204 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
205 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
206 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
207 r->main->count--; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
208 } |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
209 |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
210 return rc; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
214 ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
215 ngx_http_read_unbuffered_request_body(ngx_http_request_t *r) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
216 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
217 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
218 |
6497
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
219 #if (NGX_HTTP_V2) |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
220 if (r->stream) { |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
221 rc = ngx_http_v2_read_unbuffered_request_body(r); |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
222 |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
223 if (rc == NGX_OK) { |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
224 r->reading_body = 0; |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
225 } |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
226 |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
227 return rc; |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
228 } |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
229 #endif |
9d66d7ed2abb
HTTP/2: support for unbuffered upload of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6496
diff
changeset
|
230 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
231 if (r->connection->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
232 r->connection->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
233 return NGX_HTTP_REQUEST_TIME_OUT; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
234 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
235 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
236 rc = ngx_http_do_read_client_request_body(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
237 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
238 if (rc == NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
239 r->reading_body = 0; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
240 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
241 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
242 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
243 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
244 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
245 |
501 | 246 static void |
509 | 247 ngx_http_read_client_request_body_handler(ngx_http_request_t *r) |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
248 { |
509 | 249 ngx_int_t rc; |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
250 |
509 | 251 if (r->connection->read->timedout) { |
577 | 252 r->connection->timedout = 1; |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
253 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
299
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
254 return; |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
255 } |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
256 |
509 | 257 rc = ngx_http_do_read_client_request_body(r); |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
258 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
259 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
260 ngx_http_finalize_request(r, rc); |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
261 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
262 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
263 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
264 |
501 | 265 static ngx_int_t |
509 | 266 ngx_http_do_read_client_request_body(ngx_http_request_t *r) |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
267 { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
268 off_t rest; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
269 size_t size; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
270 ssize_t n; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
271 ngx_int_t rc; |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
272 ngx_chain_t out; |
509 | 273 ngx_connection_t *c; |
479 | 274 ngx_http_request_body_t *rb; |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
275 ngx_http_core_loc_conf_t *clcf; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
276 |
509 | 277 c = r->connection; |
479 | 278 rb = r->request_body; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
279 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
280 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
281 "http read client request body"); |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
282 |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
283 for ( ;; ) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
284 for ( ;; ) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
285 if (rb->buf->last == rb->buf->end) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
286 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
287 /* update chains */ |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
288 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
289 rc = ngx_http_request_body_filter(r, NULL); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
290 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
291 if (rc != NGX_OK) { |
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
292 return rc; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
293 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
294 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
295 if (rb->busy != NULL) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
296 if (r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
297 if (c->read->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
298 ngx_del_timer(c->read); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
299 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
300 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
301 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
302 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
303 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
304 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
305 return NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
306 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
307 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
308 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
309 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
310 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
311 rb->buf->pos = rb->buf->start; |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
312 rb->buf->last = rb->buf->start; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
313 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
314 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
315 size = rb->buf->end - rb->buf->last; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
316 rest = rb->rest - (rb->buf->last - rb->buf->pos); |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
317 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
318 if ((off_t) size > rest) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
319 size = (size_t) rest; |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
320 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
321 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
322 n = c->recv(c, rb->buf->last, size); |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
323 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
324 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
325 "http client request body recv %z", n); |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
326 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
327 if (n == NGX_AGAIN) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
328 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
329 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
330 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
331 if (n == 0) { |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
6989
diff
changeset
|
332 rb->buf->last_buf = 1; |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
333 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
334 |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
6989
diff
changeset
|
335 if (n == NGX_ERROR) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
336 c->error = 1; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
337 return NGX_HTTP_BAD_REQUEST; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
338 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
339 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
340 rb->buf->last += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
341 r->request_length += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
342 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
343 /* pass buffer to request body filter chain */ |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
344 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
345 out.buf = rb->buf; |
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
346 out.next = NULL; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
347 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
348 rc = ngx_http_request_body_filter(r, &out); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
349 |
7691
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
350 if (rc != NGX_OK) { |
08ff2e10ae92
Request body: all read data are now sent to filters.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6989
diff
changeset
|
351 return rc; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
352 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
353 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
354 if (rb->rest == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
355 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
356 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
357 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
358 if (rb->buf->last < rb->buf->end) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
359 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
360 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
361 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
362 |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
363 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1112 | 364 "http client request body rest %O", rb->rest); |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
365 |
479 | 366 if (rb->rest == 0) { |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
367 break; |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
368 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
369 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
370 if (!c->read->ready) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
371 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
372 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
373 ngx_add_timer(c->read, clcf->client_body_timeout); |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
374 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
375 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
376 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
377 } |
573 | 378 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
379 return NGX_AGAIN; |
573 | 380 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
381 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
382 |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
383 if (ngx_http_copy_pipelined_header(r, rb->buf) != NGX_OK) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
384 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
385 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
386 |
573 | 387 if (c->read->timer_set) { |
388 ngx_del_timer(c->read); | |
389 } | |
390 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
391 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
392 r->read_event_handler = ngx_http_block_reading; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
393 rb->post_handler(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
394 } |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
395 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
396 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
397 } |
633 | 398 |
399 | |
400 static ngx_int_t | |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
401 ngx_http_copy_pipelined_header(ngx_http_request_t *r, ngx_buf_t *buf) |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
402 { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
403 size_t n; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
404 ngx_buf_t *b; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
405 ngx_chain_t *cl; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
406 ngx_http_connection_t *hc; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
407 ngx_http_core_srv_conf_t *cscf; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
408 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
409 b = r->header_in; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
410 n = buf->last - buf->pos; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
411 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
412 if (buf == b || n == 0) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
413 return NGX_OK; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
414 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
415 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
416 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
417 "http body pipelined header: %uz", n); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
418 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
419 /* |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
420 * if there is a pipelined request in the client body buffer, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
421 * copy it to the r->header_in buffer if there is enough room, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
422 * or allocate a large client header buffer |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
423 */ |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
424 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
425 if (n > (size_t) (b->end - b->last)) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
426 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
427 hc = r->http_connection; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
428 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
429 if (hc->free) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
430 cl = hc->free; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
431 hc->free = cl->next; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
432 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
433 b = cl->buf; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
434 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
435 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
436 "http large header free: %p %uz", |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
437 b->pos, b->end - b->last); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
438 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
439 } else { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
440 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
441 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
442 b = ngx_create_temp_buf(r->connection->pool, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
443 cscf->large_client_header_buffers.size); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
444 if (b == NULL) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
445 return NGX_ERROR; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
446 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
447 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
448 cl = ngx_alloc_chain_link(r->connection->pool); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
449 if (cl == NULL) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
450 return NGX_ERROR; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
451 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
452 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
453 cl->buf = b; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
454 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
455 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
456 "http large header alloc: %p %uz", |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
457 b->pos, b->end - b->last); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
458 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
459 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
460 cl->next = hc->busy; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
461 hc->busy = cl; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
462 hc->nbusy++; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
463 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
464 r->header_in = b; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
465 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
466 if (n > (size_t) (b->end - b->last)) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
467 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
468 "too large pipelined header after reading body"); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
469 return NGX_ERROR; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
470 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
471 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
472 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
473 ngx_memcpy(b->last, buf->pos, n); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
474 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
475 b->last += n; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
476 r->request_length -= n; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
477 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
478 return NGX_OK; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
479 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
480 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
481 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
482 static ngx_int_t |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
483 ngx_http_write_request_body(ngx_http_request_t *r) |
633 | 484 { |
485 ssize_t n; | |
6047
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
486 ngx_chain_t *cl, *ln; |
633 | 487 ngx_temp_file_t *tf; |
488 ngx_http_request_body_t *rb; | |
489 ngx_http_core_loc_conf_t *clcf; | |
490 | |
491 rb = r->request_body; | |
492 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
493 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
494 "http write client request body, bufs %p", rb->bufs); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
495 |
633 | 496 if (rb->temp_file == NULL) { |
497 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); | |
498 if (tf == NULL) { | |
499 return NGX_ERROR; | |
500 } | |
501 | |
502 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
503 | |
504 tf->file.fd = NGX_INVALID_FILE; | |
505 tf->file.log = r->connection->log; | |
506 tf->path = clcf->client_body_temp_path; | |
507 tf->pool = r->pool; | |
508 tf->warn = "a client request body is buffered to a temporary file"; | |
637 | 509 tf->log_level = r->request_body_file_log_level; |
633 | 510 tf->persistent = r->request_body_in_persistent_file; |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
511 tf->clean = r->request_body_in_clean_file; |
633 | 512 |
513 if (r->request_body_file_group_access) { | |
1046 | 514 tf->access = 0660; |
633 | 515 } |
516 | |
517 rb->temp_file = tf; | |
4922
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
518 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
519 if (rb->bufs == NULL) { |
4922
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
520 /* empty body with r->request_body_in_file_only */ |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
521 |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
522 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
523 tf->persistent, tf->clean, tf->access) |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
524 != NGX_OK) |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
525 { |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
526 return NGX_ERROR; |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
527 } |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
528 |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
529 return NGX_OK; |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
530 } |
633 | 531 } |
532 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
533 if (rb->bufs == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
534 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
535 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
536 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
537 n = ngx_write_chain_to_temp_file(rb->temp_file, rb->bufs); |
633 | 538 |
539 /* TODO: n == 0 or not complete and level event */ | |
540 | |
541 if (n == NGX_ERROR) { | |
542 return NGX_ERROR; | |
543 } | |
544 | |
545 rb->temp_file->offset += n; | |
546 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
547 /* mark all buffers as written */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
548 |
6047
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
549 for (cl = rb->bufs; cl; /* void */) { |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
550 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
551 cl->buf->pos = cl->buf->last; |
6047
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
552 |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
553 ln = cl; |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
554 cl = cl->next; |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
555 ngx_free_chain(r->pool, ln); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
556 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
557 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
558 rb->bufs = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
559 |
633 | 560 return NGX_OK; |
561 } | |
562 | |
563 | |
564 ngx_int_t | |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
565 ngx_http_discard_request_body(ngx_http_request_t *r) |
633 | 566 { |
567 ssize_t size; | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
568 ngx_int_t rc; |
633 | 569 ngx_event_t *rev; |
570 | |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
571 if (r != r->main || r->discard_body || r->request_body) { |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
572 return NGX_OK; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
573 } |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
574 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6067
diff
changeset
|
575 #if (NGX_HTTP_V2) |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
576 if (r->stream) { |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
577 r->stream->skip_data = 1; |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
578 return NGX_OK; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
579 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
580 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
581 |
8529
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
582 #if (NGX_HTTP_QUIC) |
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
583 if (r->connection->qs) { |
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
584 return NGX_OK; |
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
585 } |
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
586 #endif |
eaea7dac3292
HTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan <arut@nginx.com>
parents:
8520
diff
changeset
|
587 |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
588 if (ngx_http_test_expect(r) != NGX_OK) { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
589 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
590 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
591 |
633 | 592 rev = r->connection->read; |
593 | |
594 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); | |
595 | |
596 if (rev->timer_set) { | |
597 ngx_del_timer(rev); | |
598 } | |
599 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
600 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
633 | 601 return NGX_OK; |
602 } | |
603 | |
604 size = r->header_in->last - r->header_in->pos; | |
605 | |
4934
b61edaa04342
Request body: fixed discard of chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4931
diff
changeset
|
606 if (size || r->headers_in.chunked) { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
607 rc = ngx_http_discard_request_body_filter(r, r->header_in); |
633 | 608 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
609 if (rc != NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
610 return rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
611 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
612 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
613 if (r->headers_in.content_length_n == 0) { |
633 | 614 return NGX_OK; |
615 } | |
616 } | |
617 | |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
618 rc = ngx_http_read_discarded_request_body(r); |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
619 |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
620 if (rc == NGX_OK) { |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
621 r->lingering_close = 0; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
622 return NGX_OK; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
623 } |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
624 |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
625 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
626 return rc; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
627 } |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
628 |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
629 /* rc == NGX_AGAIN */ |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
630 |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
631 r->read_event_handler = ngx_http_discarded_request_body_handler; |
633 | 632 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
633 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
633 | 634 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
635 } | |
636 | |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
637 r->count++; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
638 r->discard_body = 1; |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
639 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
640 return NGX_OK; |
633 | 641 } |
642 | |
643 | |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
644 void |
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
645 ngx_http_discarded_request_body_handler(ngx_http_request_t *r) |
633 | 646 { |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
647 ngx_int_t rc; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
648 ngx_msec_t timer; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
649 ngx_event_t *rev; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
650 ngx_connection_t *c; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
651 ngx_http_core_loc_conf_t *clcf; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
652 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
653 c = r->connection; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
654 rev = c->read; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
655 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
656 if (rev->timedout) { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
657 c->timedout = 1; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
658 c->error = 1; |
3213
7fc06314c684
fix ngx_http_finalize_request() code after a body has been discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3212
diff
changeset
|
659 ngx_http_finalize_request(r, NGX_ERROR); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
660 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
661 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
662 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
663 if (r->lingering_time) { |
5210
ea2ba6dbe361
Fixed lingering_time check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5199
diff
changeset
|
664 timer = (ngx_msec_t) r->lingering_time - (ngx_msec_t) ngx_time(); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
665 |
5210
ea2ba6dbe361
Fixed lingering_time check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5199
diff
changeset
|
666 if ((ngx_msec_int_t) timer <= 0) { |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
667 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
668 r->lingering_close = 0; |
3213
7fc06314c684
fix ngx_http_finalize_request() code after a body has been discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3212
diff
changeset
|
669 ngx_http_finalize_request(r, NGX_ERROR); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
670 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
671 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
672 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
673 } else { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
674 timer = 0; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
675 } |
633 | 676 |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
677 rc = ngx_http_read_discarded_request_body(r); |
633 | 678 |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
679 if (rc == NGX_OK) { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
680 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
681 r->lingering_close = 0; |
3213
7fc06314c684
fix ngx_http_finalize_request() code after a body has been discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3212
diff
changeset
|
682 ngx_http_finalize_request(r, NGX_DONE); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
683 return; |
633 | 684 } |
685 | |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
686 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
687 c->error = 1; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
688 ngx_http_finalize_request(r, NGX_ERROR); |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
689 return; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
690 } |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
691 |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
692 /* rc == NGX_AGAIN */ |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
693 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
694 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
1456 | 695 c->error = 1; |
3213
7fc06314c684
fix ngx_http_finalize_request() code after a body has been discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3212
diff
changeset
|
696 ngx_http_finalize_request(r, NGX_ERROR); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
697 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
698 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
699 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
700 if (timer) { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
701 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
702 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
703 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
704 timer *= 1000; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
705 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
706 if (timer > clcf->lingering_timeout) { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
707 timer = clcf->lingering_timeout; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
708 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
709 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
710 ngx_add_timer(rev, timer); |
633 | 711 } |
712 } | |
713 | |
714 | |
715 static ngx_int_t | |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
716 ngx_http_read_discarded_request_body(ngx_http_request_t *r) |
633 | 717 { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
718 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
719 ssize_t n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
720 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
721 ngx_buf_t b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
722 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; |
633 | 723 |
724 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
725 "http read discarded body"); | |
726 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
727 ngx_memzero(&b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
728 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
729 b.temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
730 |
3162 | 731 for ( ;; ) { |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
732 if (r->headers_in.content_length_n == 0) { |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
733 break; |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
734 } |
633 | 735 |
3162 | 736 if (!r->connection->read->ready) { |
737 return NGX_AGAIN; | |
738 } | |
739 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
740 size = (size_t) ngx_min(r->headers_in.content_length_n, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
741 NGX_HTTP_DISCARD_BUFFER_SIZE); |
633 | 742 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
743 n = r->connection->recv(r->connection, buffer, size); |
633 | 744 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
745 if (n == NGX_ERROR) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
746 r->connection->error = 1; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
747 return NGX_OK; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
748 } |
633 | 749 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
750 if (n == NGX_AGAIN) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
751 return NGX_AGAIN; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
752 } |
633 | 753 |
1422
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
754 if (n == 0) { |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
755 return NGX_OK; |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
756 } |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
757 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
758 b.pos = buffer; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
759 b.last = buffer + n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
760 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
761 rc = ngx_http_discard_request_body_filter(r, &b); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
762 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
763 if (rc != NGX_OK) { |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
764 return rc; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
765 } |
3162 | 766 } |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
767 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
768 if (ngx_http_copy_pipelined_header(r, &b) != NGX_OK) { |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
769 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
770 } |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
771 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
772 r->read_event_handler = ngx_http_block_reading; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
773 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
774 return NGX_OK; |
633 | 775 } |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
776 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
777 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
778 static ngx_int_t |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
779 ngx_http_discard_request_body_filter(ngx_http_request_t *r, ngx_buf_t *b) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
780 { |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
781 size_t size; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
782 ngx_int_t rc; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
783 ngx_http_request_body_t *rb; |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
784 ngx_http_core_srv_conf_t *cscf; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
785 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
786 if (r->headers_in.chunked) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
787 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
788 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
789 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
790 if (rb == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
791 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
792 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
793 if (rb == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
794 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
795 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
796 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
797 rb->chunked = ngx_pcalloc(r->pool, sizeof(ngx_http_chunked_t)); |
4936
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
798 if (rb->chunked == NULL) { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
799 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
800 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
801 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
802 r->request_body = rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
803 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
804 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
805 for ( ;; ) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
806 |
8404
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
807 switch (r->http_version) { |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
808 #if (NGX_HTTP_V3) |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
809 case NGX_HTTP_VERSION_30: |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
810 rc = ngx_http_v3_parse_request_body(r, b, rb->chunked); |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
811 break; |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
812 #endif |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
813 |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
814 default: /* HTTP/1.x */ |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
815 rc = ngx_http_parse_chunked(r, b, rb->chunked); |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
816 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
817 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
818 if (rc == NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
819 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
820 /* a chunk has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
821 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
822 size = b->last - b->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
823 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
824 if ((off_t) size > rb->chunked->size) { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
825 b->pos += (size_t) rb->chunked->size; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
826 rb->chunked->size = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
827 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
828 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
829 rb->chunked->size -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
830 b->pos = b->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
831 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
832 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
833 continue; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
834 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
835 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
836 if (rc == NGX_DONE) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
837 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
838 /* a whole response has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
839 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
840 r->headers_in.content_length_n = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
841 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
842 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
843 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
844 if (rc == NGX_AGAIN) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
845 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
846 /* set amount of data we want to see next time */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
847 |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
848 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
849 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
850 r->headers_in.content_length_n = ngx_max(rb->chunked->length, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
851 (off_t) cscf->large_client_header_buffers.size); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
852 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
853 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
854 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
855 /* invalid */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
856 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
857 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
858 "client sent invalid chunked body"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
859 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
860 return NGX_HTTP_BAD_REQUEST; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
861 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
862 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
863 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
864 size = b->last - b->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
865 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
866 if ((off_t) size > r->headers_in.content_length_n) { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
867 b->pos += (size_t) r->headers_in.content_length_n; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
868 r->headers_in.content_length_n = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
869 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
870 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
871 b->pos = b->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
872 r->headers_in.content_length_n -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
873 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
874 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
875 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
876 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
877 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
878 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
879 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
880 static ngx_int_t |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
881 ngx_http_test_expect(ngx_http_request_t *r) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
882 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
883 ngx_int_t n; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
884 ngx_str_t *expect; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
885 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
886 if (r->expect_tested |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
887 || r->headers_in.expect == NULL |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
6989
diff
changeset
|
888 || r->http_version != NGX_HTTP_VERSION_11) |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
889 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
890 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
891 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
892 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
893 r->expect_tested = 1; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
894 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
895 expect = &r->headers_in.expect->value; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
896 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
897 if (expect->len != sizeof("100-continue") - 1 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
898 || ngx_strncasecmp(expect->data, (u_char *) "100-continue", |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
899 sizeof("100-continue") - 1) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
900 != 0) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
901 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
902 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
903 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
904 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
905 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
906 "send 100 Continue"); |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
907 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
908 n = r->connection->send(r->connection, |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
909 (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF, |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
910 sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1); |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
911 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
912 if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
913 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
914 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
915 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
916 /* we assume that such small packet should be send successfully */ |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
917 |
6903
92e771de7d89
Request body: c->error on "100 Continue" errors (ticket #1194).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6497
diff
changeset
|
918 r->connection->error = 1; |
92e771de7d89
Request body: c->error on "100 Continue" errors (ticket #1194).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6497
diff
changeset
|
919 |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
920 return NGX_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
921 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
922 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
923 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
924 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
925 ngx_http_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
926 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
927 if (r->headers_in.chunked) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
928 return ngx_http_request_body_chunked_filter(r, in); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
929 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
930 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
931 return ngx_http_request_body_length_filter(r, in); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
932 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
933 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
934 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
935 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
936 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
937 ngx_http_request_body_length_filter(ngx_http_request_t *r, ngx_chain_t *in) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
938 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
939 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
940 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
941 ngx_buf_t *b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
942 ngx_chain_t *cl, *tl, *out, **ll; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
943 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
944 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
945 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
946 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
947 if (rb->rest == -1) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
948 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
949 "http request body content length filter"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
950 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
951 rb->rest = r->headers_in.content_length_n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
952 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
953 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
954 out = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
955 ll = &out; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
956 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
957 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
958 |
5502
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
959 if (rb->rest == 0) { |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
960 break; |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
961 } |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
962 |
8548
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
963 size = cl->buf->last - cl->buf->pos; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
964 |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
965 if (cl->buf->last_buf && (off_t) size < rb->rest) { |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
966 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
967 "client prematurely closed connection"); |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
968 r->connection->error = 1; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
969 return NGX_HTTP_BAD_REQUEST; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
970 } |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
971 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
972 tl = ngx_chain_get_free_buf(r->pool, &rb->free); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
973 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
974 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
975 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
976 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
977 b = tl->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
978 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
979 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
980 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
981 b->temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
982 b->tag = (ngx_buf_tag_t) &ngx_http_read_client_request_body; |
5110
0bbdd966a383
Request body: next upstream fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5025
diff
changeset
|
983 b->start = cl->buf->pos; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
984 b->pos = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
985 b->last = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
986 b->end = cl->buf->end; |
6067
231a5bbd9e9c
Request body: always flush buffers if request buffering is off.
Valentin Bartenev <vbart@nginx.com>
parents:
6050
diff
changeset
|
987 b->flush = r->request_body_no_buffering; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
988 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
989 if ((off_t) size < rb->rest) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
990 cl->buf->pos = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
991 rb->rest -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
992 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
993 } else { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
994 cl->buf->pos += (size_t) rb->rest; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
995 rb->rest = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
996 b->last = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
997 b->last_buf = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
998 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
999 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1000 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1001 ll = &tl->next; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1002 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1003 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
1004 rc = ngx_http_top_request_body_filter(r, out); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1005 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1006 ngx_chain_update_chains(r->pool, &rb->free, &rb->busy, &out, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1007 (ngx_buf_tag_t) &ngx_http_read_client_request_body); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1008 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1009 return rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1010 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1011 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1012 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1013 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1014 ngx_http_request_body_chunked_filter(ngx_http_request_t *r, ngx_chain_t *in) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1015 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1016 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1017 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1018 ngx_buf_t *b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1019 ngx_chain_t *cl, *out, *tl, **ll; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1020 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1021 ngx_http_core_loc_conf_t *clcf; |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1022 ngx_http_core_srv_conf_t *cscf; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1023 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1024 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1025 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1026 if (rb->rest == -1) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1027 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1028 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1029 "http request body chunked filter"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1030 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1031 rb->chunked = ngx_pcalloc(r->pool, sizeof(ngx_http_chunked_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1032 if (rb->chunked == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1033 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1034 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1035 |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1036 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1037 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1038 r->headers_in.content_length_n = 0; |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1039 rb->rest = cscf->large_client_header_buffers.size; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1040 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1041 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1042 out = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1043 ll = &out; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1044 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1045 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1046 |
7693
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1047 b = NULL; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1048 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1049 for ( ;; ) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1050 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1051 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1052 "http body chunked buf " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5588
diff
changeset
|
1053 "t:%d f:%d %p, pos %p, size: %z file: %O, size: %O", |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1054 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1055 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1056 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1057 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1058 cl->buf->file_last - cl->buf->file_pos); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1059 |
8404
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1060 switch (r->http_version) { |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1061 #if (NGX_HTTP_V3) |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1062 case NGX_HTTP_VERSION_30: |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1063 rc = ngx_http_v3_parse_request_body(r, cl->buf, rb->chunked); |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1064 break; |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1065 #endif |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1066 |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1067 default: /* HTTP/1.x */ |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1068 rc = ngx_http_parse_chunked(r, cl->buf, rb->chunked); |
e5d4f057a6cb
HTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
1069 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1070 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1071 if (rc == NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1072 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1073 /* a chunk has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1074 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1075 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1076 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1077 if (clcf->client_max_body_size |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1078 && clcf->client_max_body_size |
5588
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
1079 - r->headers_in.content_length_n < rb->chunked->size) |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1080 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1081 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1082 "client intended to send too large chunked " |
5588
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
1083 "body: %O+%O bytes", |
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
1084 r->headers_in.content_length_n, |
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
1085 rb->chunked->size); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1086 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1087 r->lingering_close = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1088 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1089 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1090 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1091 |
7693
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1092 if (b |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1093 && rb->chunked->size <= 128 |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1094 && cl->buf->last - cl->buf->pos >= rb->chunked->size) |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1095 { |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1096 r->headers_in.content_length_n += rb->chunked->size; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1097 |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1098 if (rb->chunked->size < 8) { |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1099 |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1100 while (rb->chunked->size) { |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1101 *b->last++ = *cl->buf->pos++; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1102 rb->chunked->size--; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1103 } |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1104 |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1105 } else { |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1106 ngx_memmove(b->last, cl->buf->pos, rb->chunked->size); |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1107 b->last += rb->chunked->size; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1108 cl->buf->pos += rb->chunked->size; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1109 rb->chunked->size = 0; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1110 } |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1111 |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1112 continue; |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1113 } |
f5a2af0e7079
Request body: optimized handling of small chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7692
diff
changeset
|
1114 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1115 tl = ngx_chain_get_free_buf(r->pool, &rb->free); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1116 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1117 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1118 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1119 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1120 b = tl->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1121 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1122 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1123 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1124 b->temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1125 b->tag = (ngx_buf_tag_t) &ngx_http_read_client_request_body; |
5110
0bbdd966a383
Request body: next upstream fix.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5025
diff
changeset
|
1126 b->start = cl->buf->pos; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1127 b->pos = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1128 b->last = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1129 b->end = cl->buf->end; |
6067
231a5bbd9e9c
Request body: always flush buffers if request buffering is off.
Valentin Bartenev <vbart@nginx.com>
parents:
6050
diff
changeset
|
1130 b->flush = r->request_body_no_buffering; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1131 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1132 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1133 ll = &tl->next; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1134 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1135 size = cl->buf->last - cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1136 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1137 if ((off_t) size > rb->chunked->size) { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
1138 cl->buf->pos += (size_t) rb->chunked->size; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1139 r->headers_in.content_length_n += rb->chunked->size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1140 rb->chunked->size = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1141 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1142 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1143 rb->chunked->size -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1144 r->headers_in.content_length_n += size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1145 cl->buf->pos = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1146 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1147 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1148 b->last = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1149 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1150 continue; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1151 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1152 |
8548
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1153 if (rc == NGX_AGAIN && cl->buf->last_buf) { |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1154 |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1155 /* last body buffer */ |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1156 |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1157 if (rb->chunked->length > 0) { |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1158 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1159 "client prematurely closed connection"); |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1160 r->connection->error = 1; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1161 return NGX_HTTP_BAD_REQUEST; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1162 } |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1163 |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1164 rc = NGX_DONE; |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1165 } |
9ffef6054abf
HTTP/3: fixed handling request body eof.
Roman Arutyunyan <arut@nginx.com>
parents:
8529
diff
changeset
|
1166 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1167 if (rc == NGX_DONE) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1168 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1169 /* a whole response has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1170 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1171 rb->rest = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1172 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1173 tl = ngx_chain_get_free_buf(r->pool, &rb->free); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1174 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1175 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1176 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1177 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1178 b = tl->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1179 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1180 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1181 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1182 b->last_buf = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1183 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1184 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1185 ll = &tl->next; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1186 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1187 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1188 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1189 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1190 if (rc == NGX_AGAIN) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1191 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1192 /* set rb->rest, amount of data we want to see next time */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1193 |
7692
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1194 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1195 |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1196 rb->rest = ngx_max(rb->chunked->length, |
0f7f1a509113
Request body: allowed large reads on chunk boundaries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7691
diff
changeset
|
1197 (off_t) cscf->large_client_header_buffers.size); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1198 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1199 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1200 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1201 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1202 /* invalid */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1203 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1204 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1205 "client sent invalid chunked body"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1206 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1207 return NGX_HTTP_BAD_REQUEST; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1208 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1209 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1210 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
1211 rc = ngx_http_top_request_body_filter(r, out); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1212 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1213 ngx_chain_update_chains(r->pool, &rb->free, &rb->busy, &out, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1214 (ngx_buf_tag_t) &ngx_http_read_client_request_body); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1215 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1216 return rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1217 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1218 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1219 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
1220 ngx_int_t |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1221 ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1222 { |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1223 ngx_buf_t *b; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1224 ngx_chain_t *cl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1225 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1226 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1227 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1228 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1229 #if (NGX_DEBUG) |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1230 |
6904
5e2423bce883
Request body: commented out debug printing of old buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6903
diff
changeset
|
1231 #if 0 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1232 for (cl = rb->bufs; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1233 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1234 "http body old buf t:%d f:%d %p, pos %p, size: %z " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5588
diff
changeset
|
1235 "file: %O, size: %O", |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1236 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1237 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1238 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1239 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1240 cl->buf->file_last - cl->buf->file_pos); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1241 } |
6904
5e2423bce883
Request body: commented out debug printing of old buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6903
diff
changeset
|
1242 #endif |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1243 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1244 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1245 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1246 "http body new buf t:%d f:%d %p, pos %p, size: %z " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5588
diff
changeset
|
1247 "file: %O, size: %O", |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1248 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1249 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1250 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1251 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1252 cl->buf->file_last - cl->buf->file_pos); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1253 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1254 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1255 #endif |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1256 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1257 /* TODO: coalesce neighbouring buffers */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1258 |
4936
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1259 if (ngx_chain_add_copy(r->pool, &rb->bufs, in) != NGX_OK) { |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1260 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1261 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1262 |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1263 if (r->request_body_no_buffering) { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1264 return NGX_OK; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1265 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1266 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1267 if (rb->rest > 0) { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1268 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1269 if (rb->buf && rb->buf->last == rb->buf->end |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1270 && ngx_http_write_request_body(r) != NGX_OK) |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1271 { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1272 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1273 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1274 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1275 return NGX_OK; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1276 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1277 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1278 /* rb->rest == 0 */ |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1279 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1280 if (rb->temp_file || r->request_body_in_file_only) { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1281 |
6048
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1282 if (ngx_http_write_request_body(r) != NGX_OK) { |
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1283 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1284 } |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1285 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1286 if (rb->temp_file->file.offset != 0) { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1287 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1288 cl = ngx_chain_get_free_buf(r->pool, &rb->free); |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1289 if (cl == NULL) { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1290 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1291 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1292 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1293 b = cl->buf; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1294 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1295 ngx_memzero(b, sizeof(ngx_buf_t)); |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1296 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1297 b->in_file = 1; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1298 b->file_last = rb->temp_file->file.offset; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1299 b->file = &rb->temp_file->file; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1300 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1301 rb->bufs = cl; |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1302 } |
6048
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1303 } |
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1304 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1305 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1306 } |