Mercurial > hg > nginx-quic
annotate src/http/ngx_http_request_body.c @ 1023:68cc5e2e1a5d
make global the rbtree color handling macros
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 12 Jan 2007 19:48:30 +0000 |
parents | 790ed4eb762e |
children | bb139aba3199 |
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> |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
9 #include <ngx_event.h> |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
10 #include <ngx_http.h> |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
509 | 13 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); |
14 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); | |
633 | 15 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, |
16 ngx_chain_t *body); | |
17 static void ngx_http_finalize_request_body(ngx_http_request_t *r, ngx_int_t rc); | |
18 static void ngx_http_read_discarded_body_handler(ngx_http_request_t *r); | |
19 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r); | |
20 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
21 |
479 | 22 /* |
23 * on completion ngx_http_read_client_request_body() adds to | |
24 * r->request_body->bufs one or two bufs: | |
25 * *) one memory buf that was preread in r->header_in; | |
26 * *) one memory or file buf that contains the rest of the body | |
27 */ | |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
82
diff
changeset
|
28 |
501 | 29 ngx_int_t |
30 ngx_http_read_client_request_body(ngx_http_request_t *r, | |
31 ngx_http_client_body_handler_pt post_handler) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
32 { |
663 | 33 size_t preread; |
34 ssize_t size; | |
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
|
35 ngx_buf_t *b; |
633 | 36 ngx_chain_t *cl, **next; |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
37 ngx_temp_file_t *tf; |
479 | 38 ngx_http_request_body_t *rb; |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
39 ngx_http_core_loc_conf_t *clcf; |
297
ee394e997c77
nginx-0.0.3-2004-03-29-21:43:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
296
diff
changeset
|
40 |
537 | 41 if (r->request_body || r->discard_body) { |
509 | 42 post_handler(r); |
43 return NGX_OK; | |
44 } | |
45 | |
501 | 46 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); |
47 if (rb == NULL) { | |
479 | 48 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
49 } | |
50 | |
51 r->request_body = rb; | |
52 | |
725
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
53 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
|
54 post_handler(r); |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
55 return NGX_OK; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
56 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
57 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
58 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
|
59 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
60 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
|
61 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
62 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
|
63 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
|
64 if (tf == NULL) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
65 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
66 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
67 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
68 tf->file.fd = NGX_INVALID_FILE; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
69 tf->file.log = r->connection->log; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
70 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
|
71 tf->pool = r->pool; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
72 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
|
73 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
|
74 tf->persistent = r->request_body_in_persistent_file; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
75 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
76 if (r->request_body_file_group_access) { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
77 tf->mode = 0660; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
78 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
79 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
80 rb->temp_file = tf; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
81 |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
82 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
83 tf->persistent, tf->mode) |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
84 != NGX_OK) |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
85 { |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
86 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
87 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
88 } |
86862ad988da
fix segfault when zero length file is PUT
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
89 |
479 | 90 post_handler(r); |
91 return NGX_OK; | |
92 } | |
93 | |
94 rb->post_handler = post_handler; | |
95 | |
96 /* | |
97 * set by ngx_pcalloc(): | |
98 * | |
99 * rb->bufs = NULL; | |
100 * rb->buf = NULL; | |
101 * rb->rest = 0; | |
102 */ | |
103 | |
633 | 104 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
|
105 |
633 | 106 if (preread) { |
296
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
107 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
108 /* 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
|
109 |
633 | 110 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
111 "http client request body preread %uz", preread); | |
112 | |
501 | 113 b = ngx_calloc_buf(r->pool); |
114 if (b == NULL) { | |
479 | 115 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
116 } | |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 |
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
|
118 b->temporary = 1; |
633 | 119 b->start = r->header_in->pos; |
120 b->pos = r->header_in->pos; | |
121 b->last = r->header_in->last; | |
122 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
|
123 |
501 | 124 rb->bufs = ngx_alloc_chain_link(r->pool); |
125 if (rb->bufs == NULL) { | |
479 | 126 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
127 } | |
128 | |
129 rb->bufs->buf = b; | |
130 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
|
131 |
667 | 132 rb->buf = b; |
133 | |
665 | 134 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
|
135 |
bfe099e3f5b4
nginx-0.0.3-2004-03-26-19:13:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
136 /* 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
|
137 |
663 | 138 r->header_in->pos += (size_t) r->headers_in.content_length_n; |
475 | 139 r->request_length += r->headers_in.content_length_n; |
299
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
140 |
633 | 141 if (r->request_body_in_file_only) { |
142 if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) { | |
143 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
144 } | |
145 } | |
146 | |
479 | 147 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
|
148 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
149 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 } |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
151 |
633 | 152 /* |
153 * to not consider the body as pipelined request in | |
154 * ngx_http_set_keepalive() | |
155 */ | |
162
96993d4d5067
nginx-0.0.1-2003-10-28-00:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
156 r->header_in->pos = r->header_in->last; |
633 | 157 |
158 r->request_length += preread; | |
159 | |
160 rb->rest = r->headers_in.content_length_n - preread; | |
161 | |
665 | 162 if (rb->rest <= (off_t) (b->end - b->last)) { |
633 | 163 |
164 /* the whole request body may be placed in r->header_in */ | |
165 | |
166 r->read_event_handler = ngx_http_read_client_request_body_handler; | |
167 | |
168 return ngx_http_do_read_client_request_body(r); | |
169 } | |
170 | |
171 next = &rb->bufs->next; | |
172 | |
173 } else { | |
174 b = NULL; | |
175 rb->rest = r->headers_in.content_length_n; | |
176 next = &rb->bufs; | |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
633 | 179 size = clcf->client_body_buffer_size; |
180 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
|
181 |
663 | 182 if (rb->rest < size) { |
183 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
|
184 |
633 | 185 if (r->request_body_in_single_buf) { |
186 size += preread; | |
187 } | |
188 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
189 } else { |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
299
diff
changeset
|
190 size = clcf->client_body_buffer_size; |
633 | 191 |
192 /* disable copying buffer for r->request_body_in_single_buf */ | |
193 b = NULL; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
194 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
195 |
501 | 196 rb->buf = ngx_create_temp_buf(r->pool, size); |
197 if (rb->buf == NULL) { | |
479 | 198 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
199 } | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
200 |
501 | 201 cl = ngx_alloc_chain_link(r->pool); |
202 if (cl == NULL) { | |
479 | 203 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
204 } | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
205 |
479 | 206 cl->buf = rb->buf; |
207 cl->next = NULL; | |
208 | |
633 | 209 if (b && r->request_body_in_single_buf) { |
210 size = b->last - b->pos; | |
211 ngx_memcpy(rb->buf->pos, b->pos, size); | |
212 rb->buf->last += size; | |
213 | |
214 next = &rb->bufs; | |
215 } | |
216 | |
217 *next = cl; | |
218 | |
219 if (r->request_body_in_file_only || r->request_body_in_single_buf) { | |
220 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
|
221 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
222 } else { |
633 | 223 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
|
224 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
225 |
509 | 226 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
|
227 |
509 | 228 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
|
229 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 |
501 | 232 static void |
509 | 233 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
|
234 { |
509 | 235 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
|
236 |
509 | 237 if (r->connection->read->timedout) { |
577 | 238 r->connection->timedout = 1; |
633 | 239 ngx_http_finalize_request_body(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
|
240 return; |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
241 } |
46b7eeb8a116
nginx-0.0.3-2004-03-30-19:59:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
242 |
509 | 243 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
|
244 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
245 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
633 | 246 ngx_http_finalize_request_body(r, rc); |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
247 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
248 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
249 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
250 |
501 | 251 static ngx_int_t |
509 | 252 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
|
253 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
254 size_t size; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
171
diff
changeset
|
255 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
|
256 ngx_buf_t *b; |
509 | 257 ngx_connection_t *c; |
479 | 258 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
|
259 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
|
260 |
509 | 261 c = r->connection; |
479 | 262 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
|
263 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
264 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
|
265 "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
|
266 |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
267 for ( ;; ) { |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
268 for ( ;; ) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
269 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
|
270 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
271 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
|
272 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
273 } |
479 | 274 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
275 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
|
276 rb->buf->last = rb->buf->start; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
277 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
278 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
279 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
|
280 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
281 if ((off_t) size > rb->rest) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
282 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
|
283 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
284 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
285 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
|
286 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
287 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
|
288 "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
|
289 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
290 if (n == NGX_AGAIN) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
291 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
292 } |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
293 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
294 if (n == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
295 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
|
296 "client closed prematurely connection"); |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
297 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
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 == 0 || n == NGX_ERROR) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
300 c->error = 1; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
301 return NGX_HTTP_BAD_REQUEST; |
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 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
304 rb->buf->last += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
305 rb->rest -= n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
306 r->request_length += n; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
307 |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
308 if (rb->rest == 0) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
309 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
310 } |
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 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
|
313 break; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
314 } |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
315 } |
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
316 |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
317 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
318 "http client request body rest %uz", rb->rest); |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
319 |
479 | 320 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
|
321 break; |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
322 } |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
293
diff
changeset
|
323 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
324 if (!c->read->ready) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
325 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
|
326 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
|
327 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
328 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
329 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
330 } |
573 | 331 |
841
790ed4eb762e
fix big client body receiving with deferred accept()
Igor Sysoev <igor@sysoev.ru>
parents:
725
diff
changeset
|
332 return NGX_AGAIN; |
573 | 333 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
334 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
335 |
573 | 336 if (c->read->timer_set) { |
337 ngx_del_timer(c->read); | |
338 } | |
339 | |
633 | 340 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
|
341 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
342 /* save the last part */ |
479 | 343 |
633 | 344 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
|
345 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
|
346 } |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
347 |
501 | 348 b = ngx_calloc_buf(r->pool); |
349 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
|
350 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
|
351 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 |
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
|
353 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
|
354 b->file_pos = 0; |
479 | 355 b->file_last = rb->temp_file->file.offset; |
356 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
|
357 |
479 | 358 if (rb->bufs->next) { |
359 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
|
360 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
83
diff
changeset
|
361 } else { |
479 | 362 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
|
363 } |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
364 } |
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
365 |
633 | 366 if (r->request_body_in_file_only && rb->bufs->next) { |
367 rb->bufs = rb->bufs->next; | |
368 } | |
369 | |
479 | 370 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
|
371 |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
372 return NGX_OK; |
82
fccdb921e8b8
nginx-0.0.1-2003-04-25-18:43:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
373 } |
633 | 374 |
375 | |
376 static ngx_int_t | |
377 ngx_http_write_request_body(ngx_http_request_t *r, ngx_chain_t *body) | |
378 { | |
379 ssize_t n; | |
380 ngx_temp_file_t *tf; | |
381 ngx_http_request_body_t *rb; | |
382 ngx_http_core_loc_conf_t *clcf; | |
383 | |
384 rb = r->request_body; | |
385 | |
386 if (rb->temp_file == NULL) { | |
387 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); | |
388 if (tf == NULL) { | |
389 return NGX_ERROR; | |
390 } | |
391 | |
392 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
393 | |
394 tf->file.fd = NGX_INVALID_FILE; | |
395 tf->file.log = r->connection->log; | |
396 tf->path = clcf->client_body_temp_path; | |
397 tf->pool = r->pool; | |
398 tf->warn = "a client request body is buffered to a temporary file"; | |
637 | 399 tf->log_level = r->request_body_file_log_level; |
633 | 400 tf->persistent = r->request_body_in_persistent_file; |
401 | |
402 if (r->request_body_file_group_access) { | |
403 tf->mode = 0660; | |
404 } | |
405 | |
406 rb->temp_file = tf; | |
407 } | |
408 | |
409 n = ngx_write_chain_to_temp_file(rb->temp_file, body); | |
410 | |
411 /* TODO: n == 0 or not complete and level event */ | |
412 | |
413 if (n == NGX_ERROR) { | |
414 return NGX_ERROR; | |
415 } | |
416 | |
417 rb->temp_file->offset += n; | |
418 | |
419 return NGX_OK; | |
420 } | |
421 | |
422 | |
423 static void | |
424 ngx_http_finalize_request_body(ngx_http_request_t *r, ngx_int_t rc) | |
425 { | |
426 if (r->request_body->temp_file | |
427 && r->request_body_in_persistent_file | |
428 && r->request_body_delete_incomplete_file) | |
429 { | |
430 if (ngx_delete_file(r->request_body->temp_file->file.name.data) | |
431 == NGX_FILE_ERROR) | |
432 { | |
433 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | |
434 ngx_delete_file_n " \"%s\" failed", | |
435 r->request_body->temp_file->file.name.data); | |
436 } | |
437 } | |
438 | |
439 ngx_http_finalize_request(r, rc); | |
440 } | |
441 | |
442 | |
443 ngx_int_t | |
444 ngx_http_discard_body(ngx_http_request_t *r) | |
445 { | |
446 ssize_t size; | |
447 ngx_event_t *rev; | |
448 | |
673 | 449 if (r != r->main || r->discard_body) { |
633 | 450 return NGX_OK; |
451 } | |
452 | |
453 rev = r->connection->read; | |
454 | |
455 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body"); | |
456 | |
457 if (rev->timer_set) { | |
458 ngx_del_timer(rev); | |
459 } | |
460 | |
681 | 461 r->discard_body = 1; |
462 | |
633 | 463 if (r->headers_in.content_length_n <= 0) { |
464 return NGX_OK; | |
465 } | |
466 | |
467 size = r->header_in->last - r->header_in->pos; | |
468 | |
469 if (size) { | |
470 if (r->headers_in.content_length_n > size) { | |
471 r->headers_in.content_length_n -= size; | |
472 | |
473 } else { | |
663 | 474 r->header_in->pos += (size_t) r->headers_in.content_length_n; |
633 | 475 r->headers_in.content_length_n = 0; |
476 return NGX_OK; | |
477 } | |
478 } | |
479 | |
480 r->read_event_handler = ngx_http_read_discarded_body_handler; | |
481 | |
482 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | |
483 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
484 } | |
485 | |
486 return ngx_http_read_discarded_body(r); | |
487 } | |
488 | |
489 | |
490 static void | |
491 ngx_http_read_discarded_body_handler(ngx_http_request_t *r) | |
492 { | |
493 ngx_int_t rc; | |
494 | |
495 rc = ngx_http_read_discarded_body(r); | |
496 | |
497 if (rc == NGX_AGAIN) { | |
498 if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) { | |
499 ngx_http_finalize_request(r, rc); | |
500 return; | |
501 } | |
502 } | |
503 | |
504 if (rc != NGX_OK) { | |
505 ngx_http_finalize_request(r, rc); | |
506 } | |
507 } | |
508 | |
509 | |
510 static ngx_int_t | |
511 ngx_http_read_discarded_body(ngx_http_request_t *r) | |
512 { | |
663 | 513 size_t size; |
514 ssize_t n; | |
633 | 515 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; |
516 | |
517 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
518 "http read discarded body"); | |
519 | |
520 if (r->headers_in.content_length_n == 0) { | |
521 return NGX_OK; | |
522 } | |
523 | |
663 | 524 size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ? |
525 NGX_HTTP_DISCARD_BUFFER_SIZE: | |
526 (size_t) r->headers_in.content_length_n; | |
633 | 527 |
528 n = r->connection->recv(r->connection, buffer, size); | |
529 | |
530 if (n == NGX_ERROR) { | |
531 | |
532 r->connection->error = 1; | |
533 | |
534 /* | |
535 * if a client request body is discarded then we already set | |
536 * some HTTP response code for client and we can ignore the error | |
537 */ | |
538 | |
539 return NGX_OK; | |
540 } | |
541 | |
542 if (n == NGX_AGAIN) { | |
543 return NGX_AGAIN; | |
544 } | |
545 | |
546 r->headers_in.content_length_n -= n; | |
547 | |
548 return NGX_OK; | |
549 } |