annotate src/http/ngx_http_request_body.c @ 7690:8253424d1aff

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