Mercurial > hg > nginx
annotate src/http/ngx_http_request_body.c @ 6496:887cca40ba6a
HTTP/2: rewritten handling of request body.
There are two improvements:
1. Support for request body filters;
2. Receiving of request body is started only after
the ngx_http_read_client_request_body() call.
The last one fixes the problem when the client_max_body_size value might not be
respected from the right location if the location was changed either during the
process of receiving body or after the whole body had been received.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Fri, 01 Apr 2016 15:56:03 +0300 |
parents | 3b9fe734a76c |
children | 9d66d7ed2abb |
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); | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 ngx_buf_t *b); |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
19 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r); |
633 | 20 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
21 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
|
22 ngx_chain_t *in); |
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_length_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_chunked_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); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
27 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
28 |
501 | 29 ngx_int_t |
30 ngx_http_read_client_request_body(ngx_http_request_t *r, | |
31 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
|
32 { |
663 | 33 size_t preread; |
34 ssize_t size; | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
35 ngx_int_t rc; |
5025
43cb2c9799c1
Request body: fixed client_body_in_file_only.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4937
diff
changeset
|
36 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
|
37 ngx_chain_t out; |
479 | 38 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
|
39 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
|
40 |
3049 | 41 r->main->count++; |
42 | |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
43 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
|
44 r->request_body_no_buffering = 0; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
45 post_handler(r); |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
46 return NGX_OK; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
47 } |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
48 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6067
diff
changeset
|
49 #if (NGX_HTTP_V2) |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
50 if (r->stream) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
51 r->request_body_no_buffering = 0; |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6067
diff
changeset
|
52 rc = ngx_http_v2_read_request_body(r, post_handler); |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
53 goto done; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
54 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
55 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
56 |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
57 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
|
58 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
59 goto done; |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
60 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
61 |
501 | 62 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
63 if (rb == NULL) { | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
64 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
65 goto done; |
479 | 66 } |
67 | |
68 /* | |
69 * set by ngx_pcalloc(): | |
70 * | |
71 * rb->bufs = NULL; | |
72 * rb->buf = NULL; | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
73 * rb->free = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
74 * rb->busy = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
75 * rb->chunked = NULL; |
479 | 76 */ |
77 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
78 rb->rest = -1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
79 rb->post_handler = post_handler; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
80 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
81 r->request_body = rb; |
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 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
|
84 r->request_body_no_buffering = 0; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
85 post_handler(r); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
86 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
87 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
88 |
633 | 89 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
|
90 |
633 | 91 if (preread) { |
296
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
92 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
93 /* 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
|
94 |
633 | 95 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
96 "http client request body preread %uz", preread); | |
97 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
98 out.buf = r->header_in; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
99 out.next = NULL; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
101 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
|
102 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
103 if (rc != NGX_OK) { |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
104 goto done; |
479 | 105 } |
106 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
107 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
|
108 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
109 if (!r->headers_in.chunked |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
110 && rb->rest > 0 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
111 && 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
|
112 { |
633 | 113 /* the whole request body may be placed in r->header_in */ |
114 | |
5111
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
115 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
|
116 if (b == NULL) { |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
117 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
|
118 goto done; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
119 } |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
120 |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
121 b->temporary = 1; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
127 rb->buf = b; |
57c3f84d72ce
Request body: avoid linking rb->buf to r->header_in.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5110
diff
changeset
|
128 |
633 | 129 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
|
130 r->write_event_handler = ngx_http_request_empty_handler; |
633 | 131 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
132 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
|
133 goto done; |
633 | 134 } |
135 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
136 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
137 /* set rb->rest */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
138 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
139 if (ngx_http_request_body_filter(r, NULL) != NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
140 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
141 goto done; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
142 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
143 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
144 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
145 if (rb->rest == 0) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
146 /* the whole request body was pre-read */ |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
147 r->request_body_no_buffering = 0; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
148 post_handler(r); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
149 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
4936
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
152 if (rb->rest < 0) { |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
153 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
|
154 "negative request body rest"); |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
155 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
|
156 goto done; |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
157 } |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
158 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
159 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
|
160 |
633 | 161 size = clcf->client_body_buffer_size; |
162 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
|
163 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
164 /* TODO: honor r->request_body_in_single_buf */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
165 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
166 if (!r->headers_in.chunked && rb->rest < size) { |
663 | 167 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
|
168 |
633 | 169 if (r->request_body_in_single_buf) { |
170 size += preread; | |
171 } | |
172 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
173 } else { |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
174 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
|
175 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
176 |
501 | 177 rb->buf = ngx_create_temp_buf(r->pool, size); |
178 if (rb->buf == NULL) { | |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
179 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
180 goto done; |
479 | 181 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
182 |
509 | 183 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
|
184 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
|
185 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
186 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
|
187 |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
188 done: |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
189 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
190 if (r->request_body_no_buffering |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
191 && (rc == NGX_OK || rc == NGX_AGAIN)) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
192 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
193 if (rc == NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
194 r->request_body_no_buffering = 0; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
195 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
196 } else { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
197 /* rc == NGX_AGAIN */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
198 r->reading_body = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
199 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
200 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
201 r->read_event_handler = ngx_http_block_reading; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
202 post_handler(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
203 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
204 |
4923
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
205 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
206 r->main->count--; |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
207 } |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
208 |
57174af2e695
Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4922
diff
changeset
|
209 return rc; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
213 ngx_int_t |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
214 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
|
215 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
216 ngx_int_t rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
217 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
218 if (r->connection->read->timedout) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
219 r->connection->timedout = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
220 return NGX_HTTP_REQUEST_TIME_OUT; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
221 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
222 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
223 rc = ngx_http_do_read_client_request_body(r); |
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 if (rc == NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
226 r->reading_body = 0; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
227 } |
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 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
230 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
231 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
232 |
501 | 233 static void |
509 | 234 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
|
235 { |
509 | 236 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
|
237 |
509 | 238 if (r->connection->read->timedout) { |
577 | 239 r->connection->timedout = 1; |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
240 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
|
241 return; |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
242 } |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
243 |
509 | 244 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
|
245 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
246 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
247 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
|
248 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
249 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
250 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
251 |
501 | 252 static ngx_int_t |
509 | 253 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
|
254 { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
255 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
|
256 size_t size; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
257 ssize_t n; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
258 ngx_int_t rc; |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
259 ngx_chain_t out; |
509 | 260 ngx_connection_t *c; |
479 | 261 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
|
262 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
|
263 |
509 | 264 c = r->connection; |
479 | 265 rb = r->request_body; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
267 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
|
268 "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
|
269 |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
270 for ( ;; ) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
271 for ( ;; ) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
272 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
|
273 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
274 if (rb->buf->pos != rb->buf->last) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
275 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
276 /* pass buffer to request body filter chain */ |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
277 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
278 out.buf = rb->buf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
279 out.next = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
280 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
281 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
|
282 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
283 if (rc != NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
284 return rc; |
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 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
287 } else { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
288 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
289 /* update chains */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
290 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
291 rc = ngx_http_request_body_filter(r, NULL); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
292 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
293 if (rc != NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
294 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
295 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
296 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
297 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
298 if (rb->busy != NULL) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
299 if (r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
300 if (c->read->timer_set) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
301 ngx_del_timer(c->read); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
302 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
303 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
304 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
305 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
306 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
307 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
308 return NGX_AGAIN; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
309 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
310 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
311 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
312 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
313 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
314 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
|
315 rb->buf->last = rb->buf->start; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
316 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
317 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
318 size = rb->buf->end - rb->buf->last; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
319 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
|
320 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
321 if ((off_t) size > rest) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
322 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
|
323 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
324 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
325 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
|
326 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
327 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
|
328 "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
|
329 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
330 if (n == NGX_AGAIN) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
331 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
332 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
333 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
334 if (n == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
335 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
|
336 "client prematurely closed connection"); |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
337 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
338 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
339 if (n == 0 || n == NGX_ERROR) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
340 c->error = 1; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
341 return NGX_HTTP_BAD_REQUEST; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
342 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
343 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
344 rb->buf->last += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
345 r->request_length += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
346 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
347 if (n == rest) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
348 /* pass buffer to request body filter chain */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
349 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
350 out.buf = rb->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
351 out.next = NULL; |
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 rc = ngx_http_request_body_filter(r, &out); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
354 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
355 if (rc != NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
356 return rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
357 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
358 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
359 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
360 if (rb->rest == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
361 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
362 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
363 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
364 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
|
365 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
366 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
367 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
368 |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
369 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1112 | 370 "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
|
371 |
479 | 372 if (rb->rest == 0) { |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
373 break; |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
374 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
375 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
376 if (!c->read->ready) { |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
377 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
378 if (r->request_body_no_buffering |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
379 && rb->buf->pos != rb->buf->last) |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
380 { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
381 /* pass buffer to request body filter chain */ |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
382 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
383 out.buf = rb->buf; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
384 out.next = NULL; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
385 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
386 rc = ngx_http_request_body_filter(r, &out); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
387 |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
388 if (rc != NGX_OK) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
389 return rc; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
390 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
391 } |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
392 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
393 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
|
394 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
|
395 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
396 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
|
397 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
398 } |
573 | 399 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
400 return NGX_AGAIN; |
573 | 401 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
402 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
403 |
573 | 404 if (c->read->timer_set) { |
405 ngx_del_timer(c->read); | |
406 } | |
407 | |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
408 if (!r->request_body_no_buffering) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
409 r->read_event_handler = ngx_http_block_reading; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
410 rb->post_handler(r); |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6049
diff
changeset
|
411 } |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
412 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
413 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
414 } |
633 | 415 |
416 | |
417 static ngx_int_t | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
418 ngx_http_write_request_body(ngx_http_request_t *r) |
633 | 419 { |
420 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
|
421 ngx_chain_t *cl, *ln; |
633 | 422 ngx_temp_file_t *tf; |
423 ngx_http_request_body_t *rb; | |
424 ngx_http_core_loc_conf_t *clcf; | |
425 | |
426 rb = r->request_body; | |
427 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
428 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
|
429 "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
|
430 |
633 | 431 if (rb->temp_file == NULL) { |
432 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); | |
433 if (tf == NULL) { | |
434 return NGX_ERROR; | |
435 } | |
436 | |
437 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
438 | |
439 tf->file.fd = NGX_INVALID_FILE; | |
440 tf->file.log = r->connection->log; | |
441 tf->path = clcf->client_body_temp_path; | |
442 tf->pool = r->pool; | |
443 tf->warn = "a client request body is buffered to a temporary file"; | |
637 | 444 tf->log_level = r->request_body_file_log_level; |
633 | 445 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
|
446 tf->clean = r->request_body_in_clean_file; |
633 | 447 |
448 if (r->request_body_file_group_access) { | |
1046 | 449 tf->access = 0660; |
633 | 450 } |
451 | |
452 rb->temp_file = tf; | |
4922
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
453 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
454 if (rb->bufs == NULL) { |
4922
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
455 /* 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
|
456 |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
457 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
|
458 tf->persistent, tf->clean, tf->access) |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
459 != NGX_OK) |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
460 { |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
461 return NGX_ERROR; |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
462 } |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
463 |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
464 return NGX_OK; |
dfa586842962
Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4593
diff
changeset
|
465 } |
633 | 466 } |
467 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
468 if (rb->bufs == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
469 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
470 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
471 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
472 n = ngx_write_chain_to_temp_file(rb->temp_file, rb->bufs); |
633 | 473 |
474 /* TODO: n == 0 or not complete and level event */ | |
475 | |
476 if (n == NGX_ERROR) { | |
477 return NGX_ERROR; | |
478 } | |
479 | |
480 rb->temp_file->offset += n; | |
481 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
482 /* mark all buffers as written */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
483 |
6047
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
484 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
|
485 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
486 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
|
487 |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
488 ln = cl; |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
489 cl = cl->next; |
e2e609f59094
Request body: free chain links in ngx_http_write_request_body().
Maxim Dounin <mdounin@mdounin.ru>
parents:
6044
diff
changeset
|
490 ngx_free_chain(r->pool, ln); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
491 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
492 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
493 rb->bufs = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
494 |
633 | 495 return NGX_OK; |
496 } | |
497 | |
498 | |
499 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
|
500 ngx_http_discard_request_body(ngx_http_request_t *r) |
633 | 501 { |
502 ssize_t size; | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
503 ngx_int_t rc; |
633 | 504 ngx_event_t *rev; |
505 | |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
506 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
|
507 return NGX_OK; |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
508 } |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
509 |
6246
257b51c37c5a
The HTTP/2 implementation (RFC 7240, 7241).
Valentin Bartenev <vbart@nginx.com>
parents:
6067
diff
changeset
|
510 #if (NGX_HTTP_V2) |
6496
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
511 if (r->stream) { |
887cca40ba6a
HTTP/2: rewritten handling of request body.
Valentin Bartenev <vbart@nginx.com>
parents:
6420
diff
changeset
|
512 r->stream->skip_data = 1; |
5121
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
513 return NGX_OK; |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
514 } |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
515 #endif |
c0f7b94e88ba
Preliminary experimental support for SPDY draft 2.
Valentin Bartenev <vbart@nginx.com>
parents:
5111
diff
changeset
|
516 |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
517 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
|
518 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
519 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
520 |
633 | 521 rev = r->connection->read; |
522 | |
523 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); | |
524 | |
525 if (rev->timer_set) { | |
526 ngx_del_timer(rev); | |
527 } | |
528 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
529 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
633 | 530 return NGX_OK; |
531 } | |
532 | |
533 size = r->header_in->last - r->header_in->pos; | |
534 | |
4934
b61edaa04342
Request body: fixed discard of chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4931
diff
changeset
|
535 if (size || r->headers_in.chunked) { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
536 rc = ngx_http_discard_request_body_filter(r, r->header_in); |
633 | 537 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
538 if (rc != NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
539 return rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
540 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
541 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
542 if (r->headers_in.content_length_n == 0) { |
633 | 543 return NGX_OK; |
544 } | |
545 } | |
546 | |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
547 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
|
548 |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
549 if (rc == NGX_OK) { |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
550 r->lingering_close = 0; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
551 return NGX_OK; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
552 } |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
553 |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
554 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
|
555 return rc; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
556 } |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
557 |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
558 /* rc == NGX_AGAIN */ |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
559 |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
560 r->read_event_handler = ngx_http_discarded_request_body_handler; |
633 | 561 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
562 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
633 | 563 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
564 } | |
565 | |
4924
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
566 r->count++; |
caca5603bded
Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4923
diff
changeset
|
567 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
|
568 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
569 return NGX_OK; |
633 | 570 } |
571 | |
572 | |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
573 void |
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
574 ngx_http_discarded_request_body_handler(ngx_http_request_t *r) |
633 | 575 { |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
576 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
|
577 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
|
578 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
|
579 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
|
580 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
|
581 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
582 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
|
583 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
|
584 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
585 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
|
586 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
|
587 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
|
588 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
|
589 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
590 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
591 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
592 if (r->lingering_time) { |
5210
ea2ba6dbe361
Fixed lingering_time check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5199
diff
changeset
|
593 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
|
594 |
5210
ea2ba6dbe361
Fixed lingering_time check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5199
diff
changeset
|
595 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
|
596 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
597 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
|
598 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
|
599 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
600 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
601 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
602 } else { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
603 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
|
604 } |
633 | 605 |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
606 rc = ngx_http_read_discarded_request_body(r); |
633 | 607 |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
608 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
|
609 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
610 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
|
611 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
|
612 return; |
633 | 613 } |
614 | |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
615 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
|
616 c->error = 1; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
617 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
|
618 return; |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
619 } |
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
620 |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
621 /* 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
|
622 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
623 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
1456 | 624 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
|
625 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
|
626 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
627 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
628 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
629 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
|
630 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
631 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
|
632 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
633 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
|
634 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
635 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
|
636 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
|
637 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
638 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
639 ngx_add_timer(rev, timer); |
633 | 640 } |
641 } | |
642 | |
643 | |
644 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
|
645 ngx_http_read_discarded_request_body(ngx_http_request_t *r) |
633 | 646 { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
647 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
648 ssize_t n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
649 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
650 ngx_buf_t b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
651 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; |
633 | 652 |
653 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
654 "http read discarded body"); | |
655 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
656 ngx_memzero(&b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
657 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
658 b.temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
659 |
3162 | 660 for ( ;; ) { |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
661 if (r->headers_in.content_length_n == 0) { |
1369
6254b90eea4b
block reading for level events
Igor Sysoev <igor@sysoev.ru>
parents:
1367
diff
changeset
|
662 r->read_event_handler = ngx_http_block_reading; |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
663 return NGX_OK; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
664 } |
633 | 665 |
3162 | 666 if (!r->connection->read->ready) { |
667 return NGX_AGAIN; | |
668 } | |
669 | |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
670 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
|
671 NGX_HTTP_DISCARD_BUFFER_SIZE); |
633 | 672 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
673 n = r->connection->recv(r->connection, buffer, size); |
633 | 674 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
675 if (n == NGX_ERROR) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
676 r->connection->error = 1; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
677 return NGX_OK; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
678 } |
633 | 679 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
680 if (n == NGX_AGAIN) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
681 return NGX_AGAIN; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
682 } |
633 | 683 |
1422
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
684 if (n == 0) { |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
685 return NGX_OK; |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
686 } |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
687 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
688 b.pos = buffer; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
689 b.last = buffer + n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
690 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
691 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
|
692 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
693 if (rc != NGX_OK) { |
4935
7bd1c839af3b
Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4934
diff
changeset
|
694 return rc; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
695 } |
3162 | 696 } |
633 | 697 } |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
698 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
699 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
700 static ngx_int_t |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
701 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
|
702 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
703 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
704 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
705 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
706 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
707 if (r->headers_in.chunked) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
708 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
709 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
710 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
711 if (rb == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
712 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
713 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
|
714 if (rb == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
715 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
716 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
717 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
718 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
|
719 if (rb->chunked == NULL) { |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
720 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
721 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
722 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
723 r->request_body = rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
724 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
725 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
726 for ( ;; ) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
727 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
728 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
|
729 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
730 if (rc == NGX_OK) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
731 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
732 /* a chunk has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
733 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
734 size = b->last - b->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
735 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
736 if ((off_t) size > rb->chunked->size) { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
737 b->pos += (size_t) rb->chunked->size; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
738 rb->chunked->size = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
739 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
740 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
741 rb->chunked->size -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
742 b->pos = b->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
743 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
744 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
745 continue; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
746 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
747 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
748 if (rc == NGX_DONE) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
749 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
750 /* a whole response has been parsed successfully */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
751 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
752 r->headers_in.content_length_n = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
753 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
754 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
755 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
756 if (rc == NGX_AGAIN) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
757 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
758 /* 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
|
759 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
760 r->headers_in.content_length_n = rb->chunked->length; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
761 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
762 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
763 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
764 /* invalid */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
765 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
766 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
|
767 "client sent invalid chunked body"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
768 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
769 return NGX_HTTP_BAD_REQUEST; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
770 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
771 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
772 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
773 size = b->last - b->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
774 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
775 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
|
776 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
|
777 r->headers_in.content_length_n = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
778 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
779 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
780 b->pos = b->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
781 r->headers_in.content_length_n -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
782 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
783 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
784 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
785 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
786 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
787 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
788 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
789 static ngx_int_t |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
790 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
|
791 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
792 ngx_int_t n; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
793 ngx_str_t *expect; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
794 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
795 if (r->expect_tested |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
796 || r->headers_in.expect == NULL |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
797 || r->http_version < NGX_HTTP_VERSION_11) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
798 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
799 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
800 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
801 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
802 r->expect_tested = 1; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
803 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
804 expect = &r->headers_in.expect->value; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
805 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
806 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
|
807 || 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
|
808 sizeof("100-continue") - 1) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
809 != 0) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
810 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
811 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
812 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
813 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
814 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
|
815 "send 100 Continue"); |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
816 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
817 n = r->connection->send(r->connection, |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
818 (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
|
819 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
|
820 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
821 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
|
822 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
823 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
824 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
825 /* 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
|
826 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
827 return NGX_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
828 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
829 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
830 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
831 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
832 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
|
833 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
834 if (r->headers_in.chunked) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
835 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
|
836 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
837 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
838 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
|
839 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
840 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
841 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
842 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
843 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
844 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
|
845 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
846 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
847 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
848 ngx_buf_t *b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
849 ngx_chain_t *cl, *tl, *out, **ll; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
850 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
851 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
852 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
853 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
854 if (rb->rest == -1) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
855 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
|
856 "http request body content length filter"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
857 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
858 rb->rest = r->headers_in.content_length_n; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
859 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
860 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
861 out = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
862 ll = &out; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
863 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
864 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
865 |
5502
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
866 if (rb->rest == 0) { |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
867 break; |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
868 } |
4aa64f695031
Fixed "zero size buf in output" alerts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5440
diff
changeset
|
869 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
870 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
|
871 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
872 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
873 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
874 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
875 b = tl->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
876 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
877 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
878 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
879 b->temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
880 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
|
881 b->start = cl->buf->pos; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
882 b->pos = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
883 b->last = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
884 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
|
885 b->flush = r->request_body_no_buffering; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
886 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
887 size = cl->buf->last - cl->buf->pos; |
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 if ((off_t) size < rb->rest) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
890 cl->buf->pos = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
891 rb->rest -= size; |
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 } else { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
894 cl->buf->pos += (size_t) rb->rest; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
895 rb->rest = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
896 b->last = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
897 b->last_buf = 1; |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
900 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
901 ll = &tl->next; |
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 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
904 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
|
905 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
906 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
|
907 (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
|
908 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
909 return rc; |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
912 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
913 static ngx_int_t |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
914 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
|
915 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
916 size_t size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
917 ngx_int_t rc; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
918 ngx_buf_t *b; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
919 ngx_chain_t *cl, *out, *tl, **ll; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
920 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
921 ngx_http_core_loc_conf_t *clcf; |
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 rb = r->request_body; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
924 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
925 if (rb->rest == -1) { |
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 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
|
928 "http request body chunked filter"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
929 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
930 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
|
931 if (rb->chunked == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
932 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
933 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
934 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
935 r->headers_in.content_length_n = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
936 rb->rest = 3; |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
939 out = NULL; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
940 ll = &out; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
941 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
942 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
943 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
944 for ( ;; ) { |
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 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
|
947 "http body chunked buf " |
6044
b8926ba4d087
Format specifier fixed for file size of buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5588
diff
changeset
|
948 "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
|
949 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
950 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
951 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
952 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
953 cl->buf->file_last - cl->buf->file_pos); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
954 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
955 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
|
956 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
957 if (rc == NGX_OK) { |
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 /* a chunk has been parsed successfully */ |
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 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
|
962 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
963 if (clcf->client_max_body_size |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
964 && clcf->client_max_body_size |
5588
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
965 - 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
|
966 { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
967 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
|
968 "client intended to send too large chunked " |
5588
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
969 "body: %O+%O bytes", |
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
970 r->headers_in.content_length_n, |
6fc3921025f0
Request body: avoid potential overflow.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5502
diff
changeset
|
971 rb->chunked->size); |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
972 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
973 r->lingering_close = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
974 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
975 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
976 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
977 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
978 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
|
979 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
980 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
981 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
982 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
983 b = tl->buf; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
984 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
985 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
986 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
987 b->temporary = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
988 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
|
989 b->start = cl->buf->pos; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
990 b->pos = cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
991 b->last = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
992 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
|
993 b->flush = r->request_body_no_buffering; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
994 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
995 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
996 ll = &tl->next; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
997 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
998 size = cl->buf->last - cl->buf->pos; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
999 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1000 if ((off_t) size > rb->chunked->size) { |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5210
diff
changeset
|
1001 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
|
1002 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
|
1003 rb->chunked->size = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1004 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1005 } else { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1006 rb->chunked->size -= size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1007 r->headers_in.content_length_n += size; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1008 cl->buf->pos = cl->buf->last; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1009 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1010 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1011 b->last = cl->buf->pos; |
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 continue; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1014 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1015 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1016 if (rc == NGX_DONE) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1017 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1018 /* a whole response has been parsed successfully */ |
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 rb->rest = 0; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1021 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1022 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
|
1023 if (tl == NULL) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1024 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1027 b = tl->buf; |
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 ngx_memzero(b, sizeof(ngx_buf_t)); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1030 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1031 b->last_buf = 1; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1032 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1033 *ll = tl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1034 ll = &tl->next; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1035 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1036 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1037 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1038 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1039 if (rc == NGX_AGAIN) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1040 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1041 /* 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
|
1042 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1043 rb->rest = rb->chunked->length; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1044 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1045 break; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1046 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1047 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1048 /* invalid */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1049 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1050 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
|
1051 "client sent invalid chunked body"); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1052 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1053 return NGX_HTTP_BAD_REQUEST; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1054 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1055 } |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1056 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
1057 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
|
1058 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1059 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
|
1060 (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
|
1061 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1062 return rc; |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1065 |
6049
42d9beeb22db
Request body: filters support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6048
diff
changeset
|
1066 ngx_int_t |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1067 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
|
1068 { |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1069 ngx_buf_t *b; |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1070 ngx_chain_t *cl; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1071 ngx_http_request_body_t *rb; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1072 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1073 rb = r->request_body; |
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 #if (NGX_DEBUG) |
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 for (cl = rb->bufs; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1078 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
|
1079 "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
|
1080 "file: %O, size: %O", |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1081 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1082 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1083 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1084 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1085 cl->buf->file_last - cl->buf->file_pos); |
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 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1088 for (cl = in; cl; cl = cl->next) { |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1089 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
|
1090 "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
|
1091 "file: %O, size: %O", |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1092 cl->buf->temporary, cl->buf->in_file, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1093 cl->buf->start, cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1094 cl->buf->last - cl->buf->pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1095 cl->buf->file_pos, |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1096 cl->buf->file_last - cl->buf->file_pos); |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1097 } |
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 #endif |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1100 |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1101 /* TODO: coalesce neighbouring buffers */ |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1102 |
4936
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1103 if (ngx_chain_add_copy(r->pool, &rb->bufs, in) != NGX_OK) { |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1104 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
240e3fb392c9
Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4935
diff
changeset
|
1105 } |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1106 |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1107 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
|
1108 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
|
1109 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1110 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1111 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
|
1112 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1113 if (rb->buf && rb->buf->last == rb->buf->end |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1114 && 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
|
1115 { |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1116 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
|
1117 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1118 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1119 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
|
1120 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1121 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1122 /* 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
|
1123 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1124 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
|
1125 |
6048
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1126 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
|
1127 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
|
1128 } |
6420
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1129 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1130 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
|
1131 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1132 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
|
1133 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
|
1134 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
|
1135 } |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1136 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1137 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
|
1138 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1139 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
|
1140 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1141 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
|
1142 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
|
1143 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
|
1144 |
3b9fe734a76c
Request body: moved handling of the last part in the save filter.
Valentin Bartenev <vbart@nginx.com>
parents:
6336
diff
changeset
|
1145 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
|
1146 } |
6048
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1147 } |
9e231d4cecca
Request body: moved request body writing to save filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6047
diff
changeset
|
1148 |
4930
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1149 return NGX_OK; |
6f085bfcdb4d
Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4924
diff
changeset
|
1150 } |