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