Mercurial > hg > nginx-quic
annotate src/http/ngx_http_request_body.c @ 4313:e7db97bfac25
Added support for IP-literal in the Host header and request line (ticket #1).
Additional parsing logic added to correctly handle RFC 3986 compliant IPv6 and
IPvFuture characters enclosed in square brackets.
The host validation was completely rewritten. The behavior for non IP literals
was changed in a more proper and safer way:
- Host part is now delimited either by the first colon or by the end of string
if there's no colon. Previously the last colon was used as delimiter which
allowed substitution of a port number in the $host variable.
(e.g. Host: 127.0.0.1:9000:80)
- Fixed stripping of the ending dot in the Host header when the host was also
followed by a port number.
(e.g. Host: nginx.com.:80)
- Fixed upper case characters detection. Previously it was broken which led to
wasting memory and CPU.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 28 Nov 2011 09:15:33 +0000 |
parents | cf334deeea66 |
children | d620f497c50f |
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 |
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
|
4 */ |
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 |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
7 #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
|
8 #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
|
9 #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
|
10 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
509 | 12 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); |
13 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); | |
633 | 14 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, |
15 ngx_chain_t *body); | |
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); |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
17 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r); |
633 | 18 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
19 |
479 | 20 /* |
21 * on completion ngx_http_read_client_request_body() adds to | |
22 * r->request_body->bufs one or two bufs: | |
23 * *) one memory buf that was preread in r->header_in; | |
24 * *) one memory or file buf that contains the rest of the body | |
25 */ | |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
26 |
501 | 27 ngx_int_t |
28 ngx_http_read_client_request_body(ngx_http_request_t *r, | |
29 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
|
30 { |
663 | 31 size_t preread; |
32 ssize_t size; | |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
33 ngx_buf_t *b; |
633 | 34 ngx_chain_t *cl, **next; |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
35 ngx_temp_file_t *tf; |
479 | 36 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
|
37 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
|
38 |
3049 | 39 r->main->count++; |
40 | |
537 | 41 if (r->request_body || r->discard_body) { |
509 | 42 post_handler(r); |
43 return NGX_OK; | |
44 } | |
45 | |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
46 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
|
47 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
48 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
49 |
501 | 50 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
51 if (rb == NULL) { | |
479 | 52 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
53 } | |
54 | |
55 r->request_body = rb; | |
56 | |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
57 if (r->headers_in.content_length_n < 0) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
58 post_handler(r); |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
59 return NGX_OK; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
60 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
61 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
62 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
63 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
64 if (r->headers_in.content_length_n == 0) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
65 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
66 if (r->request_body_in_file_only) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
67 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
68 if (tf == NULL) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
69 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
70 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
71 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
72 tf->file.fd = NGX_INVALID_FILE; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
73 tf->file.log = r->connection->log; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
74 tf->path = clcf->client_body_temp_path; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
75 tf->pool = r->pool; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
76 tf->warn = "a client request body is buffered to a temporary file"; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
77 tf->log_level = r->request_body_file_log_level; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
78 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
|
79 tf->clean = r->request_body_in_clean_file; |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
80 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
81 if (r->request_body_file_group_access) { |
1046 | 82 tf->access = 0660; |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
83 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
84 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
85 rb->temp_file = tf; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
86 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
87 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
88 tf->persistent, tf->clean, tf->access) |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
89 != NGX_OK) |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
90 { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
91 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
92 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
93 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
94 |
479 | 95 post_handler(r); |
1290 | 96 |
479 | 97 return NGX_OK; |
98 } | |
99 | |
100 rb->post_handler = post_handler; | |
101 | |
102 /* | |
103 * set by ngx_pcalloc(): | |
104 * | |
105 * rb->bufs = NULL; | |
106 * rb->buf = NULL; | |
107 * rb->rest = 0; | |
108 */ | |
109 | |
633 | 110 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
|
111 |
633 | 112 if (preread) { |
296
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
113 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
114 /* 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
|
115 |
633 | 116 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
117 "http client request body preread %uz", preread); | |
118 | |
501 | 119 b = ngx_calloc_buf(r->pool); |
120 if (b == NULL) { | |
479 | 121 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
122 } | |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
124 b->temporary = 1; |
633 | 125 b->start = r->header_in->pos; |
126 b->pos = r->header_in->pos; | |
127 b->last = r->header_in->last; | |
128 b->end = r->header_in->end; | |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
501 | 130 rb->bufs = ngx_alloc_chain_link(r->pool); |
131 if (rb->bufs == NULL) { | |
479 | 132 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
133 } | |
134 | |
135 rb->bufs->buf = b; | |
136 rb->bufs->next = NULL; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
137 |
667 | 138 rb->buf = b; |
139 | |
665 | 140 if ((off_t) preread >= r->headers_in.content_length_n) { |
296
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
141 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
142 /* the whole request body was pre-read */ |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
143 |
663 | 144 r->header_in->pos += (size_t) r->headers_in.content_length_n; |
475 | 145 r->request_length += r->headers_in.content_length_n; |
4005
e56c1e9873cb
Correctly set body if it's preread and there are extra data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3214
diff
changeset
|
146 b->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
|
147 |
633 | 148 if (r->request_body_in_file_only) { |
149 if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) { | |
150 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
151 } | |
152 } | |
153 | |
479 | 154 post_handler(r); |
299
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
155 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
156 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
158 |
633 | 159 /* |
160 * to not consider the body as pipelined request in | |
161 * ngx_http_set_keepalive() | |
162 */ | |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
163 r->header_in->pos = r->header_in->last; |
633 | 164 |
165 r->request_length += preread; | |
166 | |
167 rb->rest = r->headers_in.content_length_n - preread; | |
168 | |
665 | 169 if (rb->rest <= (off_t) (b->end - b->last)) { |
633 | 170 |
171 /* the whole request body may be placed in r->header_in */ | |
172 | |
1065
9039e845e532
fix segfault when a request body fits in r->header_in and
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
173 rb->to_write = rb->bufs; |
9039e845e532
fix segfault when a request body fits in r->header_in and
Igor Sysoev <igor@sysoev.ru>
parents:
1046
diff
changeset
|
174 |
633 | 175 r->read_event_handler = ngx_http_read_client_request_body_handler; |
176 | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
177 return ngx_http_do_read_client_request_body(r); |
633 | 178 } |
179 | |
180 next = &rb->bufs->next; | |
181 | |
182 } else { | |
183 b = NULL; | |
184 rb->rest = r->headers_in.content_length_n; | |
185 next = &rb->bufs; | |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 |
633 | 188 size = clcf->client_body_buffer_size; |
189 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
|
190 |
663 | 191 if (rb->rest < size) { |
192 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
|
193 |
633 | 194 if (r->request_body_in_single_buf) { |
195 size += preread; | |
196 } | |
197 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
198 } else { |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
199 size = clcf->client_body_buffer_size; |
633 | 200 |
201 /* disable copying buffer for r->request_body_in_single_buf */ | |
202 b = NULL; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
203 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
204 |
501 | 205 rb->buf = ngx_create_temp_buf(r->pool, size); |
206 if (rb->buf == NULL) { | |
479 | 207 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
208 } | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
209 |
501 | 210 cl = ngx_alloc_chain_link(r->pool); |
211 if (cl == NULL) { | |
479 | 212 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
213 } | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
214 |
479 | 215 cl->buf = rb->buf; |
216 cl->next = NULL; | |
217 | |
633 | 218 if (b && r->request_body_in_single_buf) { |
219 size = b->last - b->pos; | |
220 ngx_memcpy(rb->buf->pos, b->pos, size); | |
221 rb->buf->last += size; | |
222 | |
223 next = &rb->bufs; | |
224 } | |
225 | |
226 *next = cl; | |
227 | |
228 if (r->request_body_in_file_only || r->request_body_in_single_buf) { | |
229 rb->to_write = rb->bufs; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
230 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
231 } else { |
633 | 232 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
233 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
234 |
509 | 235 r->read_event_handler = ngx_http_read_client_request_body_handler; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
236 |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
237 return ngx_http_do_read_client_request_body(r); |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
240 |
501 | 241 static void |
509 | 242 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
|
243 { |
509 | 244 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
|
245 |
509 | 246 if (r->connection->read->timedout) { |
577 | 247 r->connection->timedout = 1; |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
248 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
|
249 return; |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
250 } |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
251 |
509 | 252 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
|
253 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
254 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1072
diff
changeset
|
255 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
|
256 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
257 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
258 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
259 |
501 | 260 static ngx_int_t |
509 | 261 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
|
262 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
263 size_t size; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
264 ssize_t n; |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
265 ngx_buf_t *b; |
509 | 266 ngx_connection_t *c; |
479 | 267 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
|
268 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
|
269 |
509 | 270 c = r->connection; |
479 | 271 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
|
272 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
273 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
|
274 "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
|
275 |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
276 for ( ;; ) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
277 for ( ;; ) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
278 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
|
279 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
280 if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
281 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
282 } |
479 | 283 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
284 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
285 rb->buf->last = rb->buf->start; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
286 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
287 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
288 size = rb->buf->end - rb->buf->last; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
289 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
290 if ((off_t) size > rb->rest) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
291 size = (size_t) rb->rest; |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
292 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
293 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
294 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
|
295 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
296 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
|
297 "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
|
298 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
299 if (n == NGX_AGAIN) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
300 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
301 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
302 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
303 if (n == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
304 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
305 "client closed prematurely connection"); |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
306 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
307 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
308 if (n == 0 || n == NGX_ERROR) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
309 c->error = 1; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
310 return NGX_HTTP_BAD_REQUEST; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
311 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
312 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
313 rb->buf->last += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
314 rb->rest -= n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
315 r->request_length += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
316 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
317 if (rb->rest == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
318 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
319 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
320 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
321 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
|
322 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
323 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
324 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
325 |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
326 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1112 | 327 "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
|
328 |
479 | 329 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
|
330 break; |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
331 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
332 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
333 if (!c->read->ready) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
334 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
|
335 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
|
336 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
337 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
|
338 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
339 } |
573 | 340 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
341 return NGX_AGAIN; |
573 | 342 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
343 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
344 |
573 | 345 if (c->read->timer_set) { |
346 ngx_del_timer(c->read); | |
347 } | |
348 | |
633 | 349 if (rb->temp_file || r->request_body_in_file_only) { |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
351 /* save the last part */ |
479 | 352 |
633 | 353 if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) { |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
354 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
355 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
356 |
501 | 357 b = ngx_calloc_buf(r->pool); |
358 if (b == NULL) { | |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
359 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
360 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
361 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
362 b->in_file = 1; |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
363 b->file_pos = 0; |
479 | 364 b->file_last = rb->temp_file->file.offset; |
365 b->file = &rb->temp_file->file; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
366 |
479 | 367 if (rb->bufs->next) { |
368 rb->bufs->next->buf = b; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
369 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
370 } else { |
479 | 371 rb->bufs->buf = b; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
372 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
373 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
374 |
4006
87f47e05fc82
Fix body with request_body_in_single_buf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4005
diff
changeset
|
375 if (rb->bufs->next |
87f47e05fc82
Fix body with request_body_in_single_buf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4005
diff
changeset
|
376 && (r->request_body_in_file_only || r->request_body_in_single_buf)) |
87f47e05fc82
Fix body with request_body_in_single_buf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4005
diff
changeset
|
377 { |
633 | 378 rb->bufs = rb->bufs->next; |
379 } | |
380 | |
4072
cf334deeea66
Bugfix: read event was not blocked after reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4006
diff
changeset
|
381 r->read_event_handler = ngx_http_block_reading; |
cf334deeea66
Bugfix: read event was not blocked after reading body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4006
diff
changeset
|
382 |
479 | 383 rb->post_handler(r); |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
384 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
385 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
386 } |
633 | 387 |
388 | |
389 static ngx_int_t | |
390 ngx_http_write_request_body(ngx_http_request_t *r, ngx_chain_t *body) | |
391 { | |
392 ssize_t n; | |
393 ngx_temp_file_t *tf; | |
394 ngx_http_request_body_t *rb; | |
395 ngx_http_core_loc_conf_t *clcf; | |
396 | |
397 rb = r->request_body; | |
398 | |
399 if (rb->temp_file == NULL) { | |
400 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); | |
401 if (tf == NULL) { | |
402 return NGX_ERROR; | |
403 } | |
404 | |
405 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
406 | |
407 tf->file.fd = NGX_INVALID_FILE; | |
408 tf->file.log = r->connection->log; | |
409 tf->path = clcf->client_body_temp_path; | |
410 tf->pool = r->pool; | |
411 tf->warn = "a client request body is buffered to a temporary file"; | |
637 | 412 tf->log_level = r->request_body_file_log_level; |
633 | 413 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
|
414 tf->clean = r->request_body_in_clean_file; |
633 | 415 |
416 if (r->request_body_file_group_access) { | |
1046 | 417 tf->access = 0660; |
633 | 418 } |
419 | |
420 rb->temp_file = tf; | |
421 } | |
422 | |
423 n = ngx_write_chain_to_temp_file(rb->temp_file, body); | |
424 | |
425 /* TODO: n == 0 or not complete and level event */ | |
426 | |
427 if (n == NGX_ERROR) { | |
428 return NGX_ERROR; | |
429 } | |
430 | |
431 rb->temp_file->offset += n; | |
432 | |
433 return NGX_OK; | |
434 } | |
435 | |
436 | |
437 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
|
438 ngx_http_discard_request_body(ngx_http_request_t *r) |
633 | 439 { |
440 ssize_t size; | |
441 ngx_event_t *rev; | |
442 | |
673 | 443 if (r != r->main || r->discard_body) { |
633 | 444 return NGX_OK; |
445 } | |
446 | |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
447 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
|
448 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
449 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
450 |
633 | 451 rev = r->connection->read; |
452 | |
453 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); | |
454 | |
455 if (rev->timer_set) { | |
456 ngx_del_timer(rev); | |
457 } | |
458 | |
1582
227152b66458
do not discard body if it has been already read
Igor Sysoev <igor@sysoev.ru>
parents:
1456
diff
changeset
|
459 if (r->headers_in.content_length_n <= 0 || r->request_body) { |
633 | 460 return NGX_OK; |
461 } | |
462 | |
463 size = r->header_in->last - r->header_in->pos; | |
464 | |
465 if (size) { | |
466 if (r->headers_in.content_length_n > size) { | |
3212
e67d000b5337
prevent handling discarded body as a pipelined request
Igor Sysoev <igor@sysoev.ru>
parents:
3181
diff
changeset
|
467 r->header_in->pos += size; |
633 | 468 r->headers_in.content_length_n -= size; |
469 | |
470 } else { | |
663 | 471 r->header_in->pos += (size_t) r->headers_in.content_length_n; |
633 | 472 r->headers_in.content_length_n = 0; |
473 return NGX_OK; | |
474 } | |
475 } | |
476 | |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
477 r->read_event_handler = ngx_http_discarded_request_body_handler; |
633 | 478 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
479 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
633 | 480 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
481 } | |
482 | |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
483 if (ngx_http_read_discarded_request_body(r) == NGX_OK) { |
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
484 r->lingering_close = 0; |
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
485 |
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
486 } else { |
3166
b208e383657d
fix r3078: do not increase request counter if body has been just discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3162
diff
changeset
|
487 r->count++; |
3179
74b74513ed59
update r3167: do not set r->discard_body if the body has been just discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3166
diff
changeset
|
488 r->discard_body = 1; |
3166
b208e383657d
fix r3078: do not increase request counter if body has been just discarded
Igor Sysoev <igor@sysoev.ru>
parents:
3162
diff
changeset
|
489 } |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
490 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
491 return NGX_OK; |
633 | 492 } |
493 | |
494 | |
3214
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
495 void |
798a7f1d3b2f
restore discard body handler after ngx_http_set_writer() set it to
Igor Sysoev <igor@sysoev.ru>
parents:
3213
diff
changeset
|
496 ngx_http_discarded_request_body_handler(ngx_http_request_t *r) |
633 | 497 { |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
504 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
|
505 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
|
506 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
507 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
|
508 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
|
509 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
|
510 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
|
511 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
512 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
513 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
514 if (r->lingering_time) { |
1640 | 515 timer = (ngx_msec_t) (r->lingering_time - ngx_time()); |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
516 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
517 if (timer <= 0) { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
518 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
519 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
|
520 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
|
521 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
522 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
523 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
524 } else { |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
525 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
|
526 } |
633 | 527 |
1370
cc114c85be0f
rename ngx_http_discard_body() to ngx_http_discard_request_body()
Igor Sysoev <igor@sysoev.ru>
parents:
1369
diff
changeset
|
528 rc = ngx_http_read_discarded_request_body(r); |
633 | 529 |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
530 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
|
531 r->discard_body = 0; |
3181
36f6407817dc
clear r->lingering_close to disable preventively calling
Igor Sysoev <igor@sysoev.ru>
parents:
3179
diff
changeset
|
532 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
|
533 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
|
534 return; |
633 | 535 } |
536 | |
1373
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
537 /* 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
|
538 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2233
diff
changeset
|
539 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
1456 | 540 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
|
541 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
|
542 return; |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
543 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
544 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
545 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
|
546 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
547 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
|
548 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
549 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
|
550 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
551 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
|
552 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
|
553 } |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
554 |
fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
Igor Sysoev <igor@sysoev.ru>
parents:
1370
diff
changeset
|
555 ngx_add_timer(rev, timer); |
633 | 556 } |
557 } | |
558 | |
559 | |
560 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
|
561 ngx_http_read_discarded_request_body(ngx_http_request_t *r) |
633 | 562 { |
663 | 563 size_t size; |
564 ssize_t n; | |
633 | 565 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; |
566 | |
567 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
568 "http read discarded body"); | |
569 | |
3162 | 570 for ( ;; ) { |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
571 if (r->headers_in.content_length_n == 0) { |
1369
6254b90eea4b
block reading for level events
Igor Sysoev <igor@sysoev.ru>
parents:
1367
diff
changeset
|
572 r->read_event_handler = ngx_http_block_reading; |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
573 return NGX_OK; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
574 } |
633 | 575 |
3162 | 576 if (!r->connection->read->ready) { |
577 return NGX_AGAIN; | |
578 } | |
579 | |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
580 size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ? |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
581 NGX_HTTP_DISCARD_BUFFER_SIZE: |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
582 (size_t) r->headers_in.content_length_n; |
633 | 583 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
584 n = r->connection->recv(r->connection, buffer, size); |
633 | 585 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
586 if (n == NGX_ERROR) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
587 r->connection->error = 1; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
588 return NGX_OK; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
589 } |
633 | 590 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
591 if (n == NGX_AGAIN) { |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
592 return NGX_AGAIN; |
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
593 } |
633 | 594 |
1422
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
595 if (n == 0) { |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
596 return NGX_OK; |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
597 } |
65dd057f71c7
cancel discarding body on EOF
Igor Sysoev <igor@sysoev.ru>
parents:
1373
diff
changeset
|
598 |
1367
aa700583b57d
discard request body in cycle
Igor Sysoev <igor@sysoev.ru>
parents:
1290
diff
changeset
|
599 r->headers_in.content_length_n -= n; |
3162 | 600 } |
633 | 601 } |
2436
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
602 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
603 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
604 static ngx_int_t |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
605 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
|
606 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
607 ngx_int_t n; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
608 ngx_str_t *expect; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
609 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
610 if (r->expect_tested |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
611 || r->headers_in.expect == NULL |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
612 || r->http_version < NGX_HTTP_VERSION_11) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
613 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
614 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
615 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
616 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
617 r->expect_tested = 1; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
618 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
619 expect = &r->headers_in.expect->value; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
620 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
621 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
|
622 || 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
|
623 sizeof("100-continue") - 1) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
624 != 0) |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
625 { |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
626 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
627 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
628 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
629 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
|
630 "send 100 Continue"); |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
631 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
632 n = r->connection->send(r->connection, |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
633 (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
|
634 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
|
635 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
636 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
|
637 return NGX_OK; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
638 } |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
639 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
640 /* 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
|
641 |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
642 return NGX_ERROR; |
26d9d4a41e91
send "100 Continue" just before reading request body
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
643 } |