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