annotate src/http/ngx_http_request_body.c @ 4936:240e3fb392c9

Request body: error checking fixes, negative rb->rest handling. Negative rb->rest can't happen with current code, but it's good to have it handled anyway. Found by Coverity (CID 744846, 744847, 744848).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 26 Nov 2012 18:01:08 +0000
parents 7bd1c839af3b
children 3b6594a2b79f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4072
diff changeset
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
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
13 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
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
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
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);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
27 static ngx_int_t ngx_http_request_body_save_filter(ngx_http_request_t *r,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
28 ngx_chain_t *in);
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
29
83
a7e45c45a95c nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 82
diff changeset
30
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
31 ngx_int_t
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
32 ngx_http_read_client_request_body(ngx_http_request_t *r,
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
33 ngx_http_client_body_handler_pt post_handler)
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
34 {
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
35 size_t preread;
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
36 ssize_t size;
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
37 ngx_int_t rc;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
38 ngx_chain_t out;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
39 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
40 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
41
3049
67254117b774 request reference counter
Igor Sysoev <igor@sysoev.ru>
parents: 2436
diff changeset
42 r->main->count++;
67254117b774 request reference counter
Igor Sysoev <igor@sysoev.ru>
parents: 2436
diff changeset
43
537
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 527
diff changeset
44 if (r->request_body || r->discard_body) {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
45 post_handler(r);
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
46 return NGX_OK;
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
47 }
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
48
2436
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
49 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
50 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
51 goto done;
2436
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
52 }
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
53
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
54 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
55 if (rb == NULL) {
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
56 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
57 goto done;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
58 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
59
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
60 /*
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
61 * set by ngx_pcalloc():
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
62 *
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
63 * rb->bufs = NULL;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
64 * rb->buf = NULL;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
65 * rb->free = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
66 * rb->busy = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
67 * rb->chunked = NULL;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
68 */
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
69
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
70 rb->rest = -1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
71 rb->post_handler = post_handler;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
72
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
73 r->request_body = rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
74
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
75 if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
76 post_handler(r);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
77 return NGX_OK;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
78 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
79
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
80 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
81
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
82 if (preread) {
296
bfe099e3f5b4 nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
83
bfe099e3f5b4 nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
84 /* 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
85
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
86 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
87 "http client request body preread %uz", preread);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
88
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
89 out.buf = r->header_in;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
90 out.next = NULL;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
92 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
93
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
94 if (rc != NGX_OK) {
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
95 goto done;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
96 }
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
97
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
98 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
99
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
100 if (!r->headers_in.chunked
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
101 && rb->rest > 0
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
102 && 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
103 {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
104 /* the whole request body may be placed in r->header_in */
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
105
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
106 rb->buf = r->header_in;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
107 r->read_event_handler = ngx_http_read_client_request_body_handler;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
108
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
109 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
110 goto done;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
111 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
112
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
113 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
114 /* set rb->rest */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
115
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
116 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
117 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
118 goto done;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
119 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
120 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
121
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
122 if (rb->rest == 0) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
123 /* the whole request body was pre-read */
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
124
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
125 if (r->request_body_in_file_only) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
126 if (ngx_http_write_request_body(r) != NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
127 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
128 goto done;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
129 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
130 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
131
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
132 post_handler(r);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
133
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
134 return NGX_OK;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 }
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
4936
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
137 if (rb->rest < 0) {
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
138 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
139 "negative request body rest");
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
140 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
141 goto done;
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
142 }
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
143
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
144 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
145
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
146 size = clcf->client_body_buffer_size;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
147 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
148
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
149 /* TODO: honor r->request_body_in_single_buf */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
150
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
151 if (!r->headers_in.chunked && rb->rest < size) {
663
6d5c1535bb9d nginx-0.3.53-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 637
diff changeset
152 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
153
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
154 if (r->request_body_in_single_buf) {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
155 size += preread;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
156 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
157
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
158 } else {
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 299
diff changeset
159 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
160 }
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
161
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
162 rb->buf = ngx_create_temp_buf(r->pool, size);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
163 if (rb->buf == NULL) {
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
164 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
165 goto done;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
166 }
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
167
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
168 r->read_event_handler = ngx_http_read_client_request_body_handler;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169
4923
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
170 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
171
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
172 done:
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
173
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
174 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
175 r->main->count--;
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
176 }
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
177
57174af2e695 Request body: fixed socket leak on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4922
diff changeset
178 return rc;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 }
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
182 static void
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
183 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
184 {
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
185 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
186
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
187 if (r->connection->read->timedout) {
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
188 r->connection->timedout = 1;
1075
4d203f76b757 undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents: 1072
diff changeset
189 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
190 return;
46b7eeb8a116 nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 297
diff changeset
191 }
46b7eeb8a116 nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 297
diff changeset
192
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
193 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
194
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
195 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
1075
4d203f76b757 undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents: 1072
diff changeset
196 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
197 }
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
198 }
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
199
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
200
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
201 static ngx_int_t
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
202 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
203 {
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
204 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
205 size_t size;
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 171
diff changeset
206 ssize_t n;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
207 ngx_int_t rc;
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
208 ngx_buf_t *b;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
209 ngx_chain_t *cl, out;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
210 ngx_connection_t *c;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
211 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
212 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
213
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
214 c = r->connection;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
215 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
216
292
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
217 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
218 "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
219
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
220 for ( ;; ) {
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
221 for ( ;; ) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
222 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
223
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
224 /* pass buffer to request body filter chain */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
225
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
226 out.buf = rb->buf;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
227 out.next = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
228
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
229 rc = ngx_http_request_body_filter(r, &out);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
230
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
231 if (rc != NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
232 return rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
233 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
234
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
235 /* write to file */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
236
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
237 if (ngx_http_write_request_body(r) != NGX_OK) {
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
238 return NGX_HTTP_INTERNAL_SERVER_ERROR;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
239 }
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
240
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
241 /* update chains */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
242
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
243 rc = ngx_http_request_body_filter(r, NULL);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
244
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
245 if (rc != NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
246 return rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
247 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
248
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
249 if (rb->busy != NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
250 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
251 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
252
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
253 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
254 rb->buf->last = rb->buf->start;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
255 }
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
256
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
257 size = rb->buf->end - rb->buf->last;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
258 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
259
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
260 if ((off_t) size > rest) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
261 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
262 }
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
263
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
264 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
265
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
266 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
267 "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
268
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
269 if (n == NGX_AGAIN) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
270 break;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
271 }
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
272
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
273 if (n == 0) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
274 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
275 "client prematurely closed connection");
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
276 }
292
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
277
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
278 if (n == 0 || n == NGX_ERROR) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
279 c->error = 1;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
280 return NGX_HTTP_BAD_REQUEST;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
281 }
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
282
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
283 rb->buf->last += n;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
284 r->request_length += n;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
285
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
286 if (n == rest) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
287 /* pass buffer to request body filter chain */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
288
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
289 out.buf = rb->buf;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
290 out.next = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
291
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
292 rc = ngx_http_request_body_filter(r, &out);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
293
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
294 if (rc != NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
295 return rc;
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
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
299 if (rb->rest == 0) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
300 break;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
301 }
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
302
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
303 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
304 break;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
305 }
292
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
306 }
a472bfb778b3 nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
307
293
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
308 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1112
3dcc3041b5bc fix format
Igor Sysoev <igor@sysoev.ru>
parents: 1075
diff changeset
309 "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
310
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
311 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
312 break;
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 293
diff changeset
313 }
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 293
diff changeset
314
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
315 if (!c->read->ready) {
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
316 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
317 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
318
2388
722b5aff05ae use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents: 2233
diff changeset
319 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
320 return NGX_HTTP_INTERNAL_SERVER_ERROR;
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
321 }
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
322
841
790ed4eb762e fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents: 725
diff changeset
323 return NGX_AGAIN;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
324 }
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 }
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
327 if (c->read->timer_set) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
328 ngx_del_timer(c->read);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
329 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
330
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
331 if (rb->temp_file || r->request_body_in_file_only) {
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
333 /* save the last part */
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
334
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
335 if (ngx_http_write_request_body(r) != NGX_OK) {
293
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
336 return NGX_HTTP_INTERNAL_SERVER_ERROR;
162
96993d4d5067 nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 160
diff changeset
337 }
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
338
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
339 cl = 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
340 if (cl == NULL) {
293
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
341 return NGX_HTTP_INTERNAL_SERVER_ERROR;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 }
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
344 b = cl->buf;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
345
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
346 ngx_memzero(b, sizeof(ngx_buf_t));
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
347
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
348 b->in_file = 1;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
349 b->file_last = rb->temp_file->file.offset;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
350 b->file = &rb->temp_file->file;
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 83
diff changeset
351
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
352 rb->bufs = cl;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
353 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
354
4072
cf334deeea66 Bugfix: read event was not blocked after reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4006
diff changeset
355 r->read_event_handler = ngx_http_block_reading;
cf334deeea66 Bugfix: read event was not blocked after reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4006
diff changeset
356
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 475
diff changeset
357 rb->post_handler(r);
293
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
358
ec3c049681fd nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
359 return NGX_OK;
82
fccdb921e8b8 nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
361
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
362
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
363 static ngx_int_t
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
364 ngx_http_write_request_body(ngx_http_request_t *r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
365 {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
366 ssize_t n;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
367 ngx_chain_t *cl;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
368 ngx_temp_file_t *tf;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
369 ngx_http_request_body_t *rb;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
370 ngx_http_core_loc_conf_t *clcf;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
371
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
372 rb = r->request_body;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
373
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
374 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
375 "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
376
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
377 if (rb->temp_file == NULL) {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
378 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
379 if (tf == NULL) {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
380 return NGX_ERROR;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
381 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
382
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
383 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
384
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
385 tf->file.fd = NGX_INVALID_FILE;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
386 tf->file.log = r->connection->log;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
387 tf->path = clcf->client_body_temp_path;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
388 tf->pool = r->pool;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
389 tf->warn = "a client request body is buffered to a temporary file";
637
e60fe4cf1d4e nginx-0.3.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
390 tf->log_level = r->request_body_file_log_level;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
391 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
392 tf->clean = r->request_body_in_clean_file;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
393
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
394 if (r->request_body_file_group_access) {
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 841
diff changeset
395 tf->access = 0660;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
396 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
397
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
398 rb->temp_file = tf;
4922
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
399
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
400 if (rb->bufs == NULL) {
4922
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
401 /* 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
402
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
403 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
404 tf->persistent, tf->clean, tf->access)
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
405 != NGX_OK)
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
406 {
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
407 return NGX_ERROR;
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
408 }
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
409
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
410 return NGX_OK;
dfa586842962 Request body: code duplication reduced, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4593
diff changeset
411 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
412 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
413
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
414 if (rb->bufs == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
415 return NGX_OK;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
416 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
417
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
418 n = ngx_write_chain_to_temp_file(rb->temp_file, rb->bufs);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
419
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
420 /* TODO: n == 0 or not complete and level event */
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
421
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
422 if (n == NGX_ERROR) {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
423 return NGX_ERROR;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
424 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
425
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
426 rb->temp_file->offset += n;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
427
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
428 /* mark all buffers as written */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
429
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
430 for (cl = rb->bufs; cl; cl = cl->next) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
431 cl->buf->pos = cl->buf->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
432 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
433
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
434 rb->bufs = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
435
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
436 return NGX_OK;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
437 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
438
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
439
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
440 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
441 ngx_http_discard_request_body(ngx_http_request_t *r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
442 {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
443 ssize_t size;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
444 ngx_int_t rc;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
445 ngx_event_t *rev;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
446
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
447 if (r != r->main || r->discard_body || r->request_body) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
448 return NGX_OK;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
449 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
450
2436
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
451 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
452 return NGX_HTTP_INTERNAL_SERVER_ERROR;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
453 }
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
454
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
455 rev = r->connection->read;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
456
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
457 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body");
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
458
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
459 if (rev->timer_set) {
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
460 ngx_del_timer(rev);
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
461 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
462
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
463 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
464 return NGX_OK;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
465 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
466
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
467 size = r->header_in->last - r->header_in->pos;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
468
4934
b61edaa04342 Request body: fixed discard of chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4931
diff changeset
469 if (size || r->headers_in.chunked) {
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
470 rc = ngx_http_discard_request_body_filter(r, r->header_in);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
471
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
472 if (rc != NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
473 return rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
474 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
475
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
476 if (r->headers_in.content_length_n == 0) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
477 return NGX_OK;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
478 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
479 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
480
4935
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
481 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
482
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
483 if (rc == NGX_OK) {
4924
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
484 r->lingering_close = 0;
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
485 return NGX_OK;
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
486 }
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
487
4935
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
488 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
489 return rc;
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
490 }
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
491
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
492 /* rc == NGX_AGAIN */
4924
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
493
3214
798a7f1d3b2f restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents: 3213
diff changeset
494 r->read_event_handler = ngx_http_discarded_request_body_handler;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
495
2388
722b5aff05ae use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents: 2233
diff changeset
496 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
497 return NGX_HTTP_INTERNAL_SERVER_ERROR;
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
498 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
499
4924
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
500 r->count++;
caca5603bded Request body: properly handle events while discarding body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4923
diff changeset
501 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
502
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
503 return NGX_OK;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
504 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
505
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
506
3214
798a7f1d3b2f restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents: 3213
diff changeset
507 void
798a7f1d3b2f restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents: 3213
diff changeset
508 ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
509 {
1373
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
510 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
511 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
512 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
513 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
514 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
515
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
516 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
517 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
518
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
519 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
520 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
521 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
522 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
523 return;
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
524 }
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
525
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
526 if (r->lingering_time) {
1640
02a22cd5282a 64-bit time_t compatibility
Igor Sysoev <igor@sysoev.ru>
parents: 1582
diff changeset
527 timer = (ngx_msec_t) (r->lingering_time - 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
528
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
529 if (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
530 r->discard_body = 0;
3181
36f6407817dc clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents: 3179
diff changeset
531 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
532 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
533 return;
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
534 }
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
535
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
536 } else {
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
537 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
538 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
539
1370
cc114c85be0f rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents: 1369
diff changeset
540 rc = ngx_http_read_discarded_request_body(r);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
541
1373
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
542 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
543 r->discard_body = 0;
3181
36f6407817dc clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents: 3179
diff changeset
544 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
545 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
546 return;
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
547 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
548
4935
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
549 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
550 c->error = 1;
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
551 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
552 return;
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
553 }
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
554
1373
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
555 /* 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
556
2388
722b5aff05ae use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents: 2233
diff changeset
557 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
1456
698ea64f71e1 fix unlikely socket leak
Igor Sysoev <igor@sysoev.ru>
parents: 1455
diff changeset
558 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
559 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
560 return;
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
561 }
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
562
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
563 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
564
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
565 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
566
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
567 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
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 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
570 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
571 }
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
572
fdea12ffb24a discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents: 1370
diff changeset
573 ngx_add_timer(rev, timer);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
574 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
575 }
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
576
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
577
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
578 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
579 ngx_http_read_discarded_request_body(ngx_http_request_t *r)
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
580 {
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
581 size_t size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
582 ssize_t n;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
583 ngx_int_t rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
584 ngx_buf_t b;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
585 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
586
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
587 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
588 "http read discarded body");
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
589
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
590 ngx_memzero(&b, sizeof(ngx_buf_t));
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
591
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
592 b.temporary = 1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
593
3162
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
594 for ( ;; ) {
1367
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
595 if (r->headers_in.content_length_n == 0) {
1369
6254b90eea4b block reading for level events
Igor Sysoev <igor@sysoev.ru>
parents: 1367
diff changeset
596 r->read_event_handler = ngx_http_block_reading;
1367
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
597 return NGX_OK;
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
598 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
599
3162
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
600 if (!r->connection->read->ready) {
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
601 return NGX_AGAIN;
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
602 }
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
603
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
604 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
605 NGX_HTTP_DISCARD_BUFFER_SIZE);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
606
1367
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
607 n = r->connection->recv(r->connection, buffer, size);
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
608
1367
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
609 if (n == NGX_ERROR) {
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
610 r->connection->error = 1;
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
611 return NGX_OK;
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
612 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
613
1367
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
614 if (n == NGX_AGAIN) {
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
615 return NGX_AGAIN;
aa700583b57d discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents: 1290
diff changeset
616 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
617
1422
65dd057f71c7 cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents: 1373
diff changeset
618 if (n == 0) {
65dd057f71c7 cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents: 1373
diff changeset
619 return NGX_OK;
65dd057f71c7 cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents: 1373
diff changeset
620 }
65dd057f71c7 cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents: 1373
diff changeset
621
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
622 b.pos = buffer;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
623 b.last = buffer + n;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
624
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
625 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
626
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
627 if (rc != NGX_OK) {
4935
7bd1c839af3b Request body: improved handling of incorrect chunked request body.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4934
diff changeset
628 return rc;
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
629 }
3162
9140fbb2ab83 fix discarding body
Igor Sysoev <igor@sysoev.ru>
parents: 3077
diff changeset
630 }
633
f971949ffb58 nginx-0.3.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
631 }
2436
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
632
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
633
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
634 static ngx_int_t
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
635 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
636 {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
637 size_t size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
638 ngx_int_t rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
639 ngx_http_request_body_t *rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
640
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
641 if (r->headers_in.chunked) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
642
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
643 rb = r->request_body;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
644
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
645 if (rb == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
646
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
647 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
648 if (rb == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
649 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
650 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
651
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
652 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
653 if (rb->chunked == NULL) {
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
654 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
655 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
656
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
657 r->request_body = rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
658 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
659
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
660 for ( ;; ) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
661
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
662 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
663
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
664 if (rc == NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
665
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
666 /* a chunk has been parsed successfully */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
667
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
668 size = b->last - b->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
669
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
670 if ((off_t) size > rb->chunked->size) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
671 b->pos += rb->chunked->size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
672 rb->chunked->size = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
673
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
674 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
675 rb->chunked->size -= size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
676 b->pos = b->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
677 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
678
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
679 continue;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
680 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
681
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
682 if (rc == NGX_DONE) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
683
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
684 /* a whole response has been parsed successfully */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
685
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
686 r->headers_in.content_length_n = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
687 break;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
688 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
689
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
690 if (rc == NGX_AGAIN) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
691
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
692 /* 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
693
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
694 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
695 break;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
696 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
697
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
698 /* invalid */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
699
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
700 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
701 "client sent invalid chunked body");
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 return NGX_HTTP_BAD_REQUEST;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
704 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
705
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
706 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
707 size = b->last - b->pos;
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 if ((off_t) size > r->headers_in.content_length_n) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
710 b->pos += r->headers_in.content_length_n;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
711 r->headers_in.content_length_n = 0;
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 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
714 b->pos = b->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
715 r->headers_in.content_length_n -= size;
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
719 return NGX_OK;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
720 }
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 static ngx_int_t
2436
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
724 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
725 {
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
726 ngx_int_t n;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
727 ngx_str_t *expect;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
728
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
729 if (r->expect_tested
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
730 || r->headers_in.expect == NULL
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
731 || 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
732 {
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
733 return NGX_OK;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
734 }
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
735
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
736 r->expect_tested = 1;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
737
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
738 expect = &r->headers_in.expect->value;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
739
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
740 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
741 || 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
742 sizeof("100-continue") - 1)
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
743 != 0)
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
744 {
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
745 return NGX_OK;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
746 }
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
747
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
748 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
749 "send 100 Continue");
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
750
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
751 n = r->connection->send(r->connection,
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
752 (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
753 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
754
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
755 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
756 return NGX_OK;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
757 }
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
758
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
759 /* 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
760
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
761 return NGX_ERROR;
26d9d4a41e91 send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
762 }
4930
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
765 static ngx_int_t
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
766 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
767 {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
768 if (r->headers_in.chunked) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
769 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
770
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
771 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
772 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
773 }
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
776
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
777 static ngx_int_t
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
778 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
779 {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
780 size_t size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
781 ngx_int_t rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
782 ngx_buf_t *b;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
783 ngx_chain_t *cl, *tl, *out, **ll;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
784 ngx_http_request_body_t *rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
785
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
786 rb = r->request_body;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
787
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
788 if (rb->rest == -1) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
789 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
790 "http request body content length filter");
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
791
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
792 rb->rest = r->headers_in.content_length_n;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
793 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
794
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
795 out = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
796 ll = &out;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
797
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
798 for (cl = in; cl; cl = cl->next) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
799
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
800 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
801 if (tl == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
802 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
803 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
804
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
805 b = tl->buf;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
806
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
807 ngx_memzero(b, sizeof(ngx_buf_t));
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
808
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
809 b->temporary = 1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
810 b->tag = (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
811 b->start = cl->buf->start;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
812 b->pos = cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
813 b->last = cl->buf->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
814 b->end = cl->buf->end;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
815
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
816 size = cl->buf->last - cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
817
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
818 if ((off_t) size < rb->rest) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
819 cl->buf->pos = cl->buf->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
820 rb->rest -= size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
821
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
822 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
823 cl->buf->pos += rb->rest;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
824 rb->rest = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
825 b->last = cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
826 b->last_buf = 1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
827 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
828
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
829 *ll = tl;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
830 ll = &tl->next;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
831 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
832
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
833 rc = ngx_http_request_body_save_filter(r, out);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
834
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
835 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
836 (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
837
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
838 return rc;
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 static ngx_int_t
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
843 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
844 {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
845 size_t size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
846 ngx_int_t rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
847 ngx_buf_t *b;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
848 ngx_chain_t *cl, *out, *tl, **ll;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
849 ngx_http_request_body_t *rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
850 ngx_http_core_loc_conf_t *clcf;
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
856 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
857 "http request body chunked filter");
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
858
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
859 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
860 if (rb->chunked == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
861 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
862 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
863
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
864 r->headers_in.content_length_n = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
865 rb->rest = 3;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
866 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
867
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
868 out = NULL;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
869 ll = &out;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
870
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
871 for (cl = in; cl; cl = cl->next) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
872
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
873 for ( ;; ) {
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 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
876 "http body chunked buf "
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
877 "t:%d f:%d %p, pos %p, size: %z file: %O, size: %z",
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
878 cl->buf->temporary, cl->buf->in_file,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
879 cl->buf->start, cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
880 cl->buf->last - cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
881 cl->buf->file_pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
882 cl->buf->file_last - cl->buf->file_pos);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
883
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
884 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
885
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
886 if (rc == NGX_OK) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
887
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
888 /* a chunk has been parsed successfully */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
889
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
890 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
891
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
892 if (clcf->client_max_body_size
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
893 && clcf->client_max_body_size
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
894 < 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
895 {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
896 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
897 "client intended to send too large chunked "
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
898 "body: %O bytes",
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
899 r->headers_in.content_length_n
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
900 + rb->chunked->size);
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
901
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
902 r->lingering_close = 1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
903
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
904 return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
907 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
908 if (tl == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
909 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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 b = tl->buf;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
913
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
914 ngx_memzero(b, sizeof(ngx_buf_t));
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 b->temporary = 1;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
917 b->tag = (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
918 b->start = cl->buf->start;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
919 b->pos = cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
920 b->last = cl->buf->last;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
921 b->end = cl->buf->end;
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 *ll = tl;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
924 ll = &tl->next;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
925
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
926 size = cl->buf->last - cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
927
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
928 if ((off_t) size > rb->chunked->size) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
929 cl->buf->pos += rb->chunked->size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
930 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
931 rb->chunked->size = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
932
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
933 } else {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
934 rb->chunked->size -= size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
935 r->headers_in.content_length_n += size;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
936 cl->buf->pos = cl->buf->last;
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 b->last = cl->buf->pos;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
940
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
941 continue;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
942 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
943
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
944 if (rc == NGX_DONE) {
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 /* a whole response has been parsed successfully */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
947
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
948 rb->rest = 0;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
949
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
950 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
951 if (tl == NULL) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
952 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
953 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
954
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
955 b = tl->buf;
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 ngx_memzero(b, sizeof(ngx_buf_t));
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 b->last_buf = 1;
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 *ll = tl;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
962 ll = &tl->next;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
963
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
964 break;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
965 }
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 if (rc == NGX_AGAIN) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
968
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
969 /* 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
970
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
971 rb->rest = rb->chunked->length;
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 break;
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
976 /* invalid */
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 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
979 "client sent invalid chunked body");
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
980
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
981 return NGX_HTTP_BAD_REQUEST;
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 }
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 rc = ngx_http_request_body_save_filter(r, out);
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 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
988 (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
989
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
990 return rc;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
991 }
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
992
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
993
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
994 static ngx_int_t
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
995 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
996 {
4931
190fce68b6b5 Request body: unbreak build without debug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4930
diff changeset
997 #if (NGX_DEBUG)
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
998 ngx_chain_t *cl;
4931
190fce68b6b5 Request body: unbreak build without debug.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4930
diff changeset
999 #endif
4930
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1000 ngx_http_request_body_t *rb;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1001
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1002 rb = r->request_body;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1003
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1004 #if (NGX_DEBUG)
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1005
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1006 for (cl = rb->bufs; cl; cl = cl->next) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1007 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
1008 "http body old buf t:%d f:%d %p, pos %p, size: %z "
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1009 "file: %O, size: %z",
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1010 cl->buf->temporary, cl->buf->in_file,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1011 cl->buf->start, cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1012 cl->buf->last - cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1013 cl->buf->file_pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1014 cl->buf->file_last - cl->buf->file_pos);
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1017 for (cl = in; cl; cl = cl->next) {
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1018 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
1019 "http body new buf t:%d f:%d %p, pos %p, size: %z "
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1020 "file: %O, size: %z",
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1021 cl->buf->temporary, cl->buf->in_file,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1022 cl->buf->start, cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1023 cl->buf->last - cl->buf->pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1024 cl->buf->file_pos,
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1025 cl->buf->file_last - cl->buf->file_pos);
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
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1028 #endif
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1029
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1030 /* TODO: coalesce neighbouring buffers */
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1031
4936
240e3fb392c9 Request body: error checking fixes, negative rb->rest handling.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4935
diff changeset
1032 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
1033 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
1034 }
4930
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 return NGX_OK;
6f085bfcdb4d Request body: chunked transfer encoding support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4924
diff changeset
1037 }