Mercurial > hg > nginx
comparison src/http/ngx_http_request_body.c @ 1075:4d203f76b757
undo "client_body_in_file_only any"
and introduce "client_body_in_file_only clean"
introduce ngx_pool_delete_file() to not break a possible third-party
ngx_pool_cleanup_file() usage that may lead to an removal of the useful files
delete unnecessary ngx_http_finalize_request_body()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 25 Jan 2007 08:45:04 +0000 |
parents | f303d33f3927 |
children | 3dcc3041b5bc |
comparison
equal
deleted
inserted
replaced
1074:8164f479b362 | 1075:4d203f76b757 |
---|---|
12 | 12 |
13 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); | 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); | 14 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r); |
15 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, | 15 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, |
16 ngx_chain_t *body); | 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); | 17 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); | 18 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r); |
20 | 19 |
21 | 20 |
22 /* | 21 /* |
30 ngx_http_read_client_request_body(ngx_http_request_t *r, | 29 ngx_http_read_client_request_body(ngx_http_request_t *r, |
31 ngx_http_client_body_handler_pt post_handler) | 30 ngx_http_client_body_handler_pt post_handler) |
32 { | 31 { |
33 size_t preread; | 32 size_t preread; |
34 ssize_t size; | 33 ssize_t size; |
35 ngx_int_t rc; | |
36 ngx_buf_t *b; | 34 ngx_buf_t *b; |
37 ngx_chain_t *cl, **next; | 35 ngx_chain_t *cl, **next; |
38 ngx_temp_file_t *tf; | 36 ngx_temp_file_t *tf; |
39 ngx_http_request_body_t *rb; | 37 ngx_http_request_body_t *rb; |
40 ngx_http_core_loc_conf_t *clcf; | 38 ngx_http_core_loc_conf_t *clcf; |
71 tf->path = clcf->client_body_temp_path; | 69 tf->path = clcf->client_body_temp_path; |
72 tf->pool = r->pool; | 70 tf->pool = r->pool; |
73 tf->warn = "a client request body is buffered to a temporary file"; | 71 tf->warn = "a client request body is buffered to a temporary file"; |
74 tf->log_level = r->request_body_file_log_level; | 72 tf->log_level = r->request_body_file_log_level; |
75 tf->persistent = r->request_body_in_persistent_file; | 73 tf->persistent = r->request_body_in_persistent_file; |
74 tf->clean = r->request_body_in_clean_file; | |
76 | 75 |
77 if (r->request_body_file_group_access) { | 76 if (r->request_body_file_group_access) { |
78 tf->access = 0660; | 77 tf->access = 0660; |
79 } | 78 } |
80 | 79 |
81 rb->temp_file = tf; | 80 rb->temp_file = tf; |
82 | 81 |
83 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, | 82 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
84 tf->persistent, tf->access) | 83 tf->persistent, tf->clean, tf->access) |
85 != NGX_OK) | 84 != NGX_OK) |
86 { | 85 { |
87 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 86 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
88 } | 87 } |
89 } | 88 } |
166 | 165 |
167 rb->to_write = rb->bufs; | 166 rb->to_write = rb->bufs; |
168 | 167 |
169 r->read_event_handler = ngx_http_read_client_request_body_handler; | 168 r->read_event_handler = ngx_http_read_client_request_body_handler; |
170 | 169 |
171 rc = ngx_http_do_read_client_request_body(r); | 170 return ngx_http_do_read_client_request_body(r); |
172 | |
173 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
174 ngx_http_finalize_request_body(r, rc); | |
175 return NGX_DONE; | |
176 } | |
177 | |
178 return rc; | |
179 } | 171 } |
180 | 172 |
181 next = &rb->bufs->next; | 173 next = &rb->bufs->next; |
182 | 174 |
183 } else { | 175 } else { |
233 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs; | 225 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs; |
234 } | 226 } |
235 | 227 |
236 r->read_event_handler = ngx_http_read_client_request_body_handler; | 228 r->read_event_handler = ngx_http_read_client_request_body_handler; |
237 | 229 |
238 rc = ngx_http_do_read_client_request_body(r); | 230 return ngx_http_do_read_client_request_body(r); |
239 | |
240 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
241 ngx_http_finalize_request_body(r, rc); | |
242 return NGX_DONE; | |
243 } | |
244 | |
245 return rc; | |
246 } | 231 } |
247 | 232 |
248 | 233 |
249 static void | 234 static void |
250 ngx_http_read_client_request_body_handler(ngx_http_request_t *r) | 235 ngx_http_read_client_request_body_handler(ngx_http_request_t *r) |
251 { | 236 { |
252 ngx_int_t rc; | 237 ngx_int_t rc; |
253 | 238 |
254 if (r->connection->read->timedout) { | 239 if (r->connection->read->timedout) { |
255 r->connection->timedout = 1; | 240 r->connection->timedout = 1; |
256 ngx_http_finalize_request_body(r, NGX_HTTP_REQUEST_TIME_OUT); | 241 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
257 return; | 242 return; |
258 } | 243 } |
259 | 244 |
260 rc = ngx_http_do_read_client_request_body(r); | 245 rc = ngx_http_do_read_client_request_body(r); |
261 | 246 |
262 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | 247 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
263 ngx_http_finalize_request_body(r, rc); | 248 ngx_http_finalize_request(r, rc); |
264 } | 249 } |
265 } | 250 } |
266 | 251 |
267 | 252 |
268 static ngx_int_t | 253 static ngx_int_t |
413 tf->path = clcf->client_body_temp_path; | 398 tf->path = clcf->client_body_temp_path; |
414 tf->pool = r->pool; | 399 tf->pool = r->pool; |
415 tf->warn = "a client request body is buffered to a temporary file"; | 400 tf->warn = "a client request body is buffered to a temporary file"; |
416 tf->log_level = r->request_body_file_log_level; | 401 tf->log_level = r->request_body_file_log_level; |
417 tf->persistent = r->request_body_in_persistent_file; | 402 tf->persistent = r->request_body_in_persistent_file; |
403 tf->clean = r->request_body_in_clean_file; | |
418 | 404 |
419 if (r->request_body_file_group_access) { | 405 if (r->request_body_file_group_access) { |
420 tf->access = 0660; | 406 tf->access = 0660; |
421 } | 407 } |
422 | 408 |
432 } | 418 } |
433 | 419 |
434 rb->temp_file->offset += n; | 420 rb->temp_file->offset += n; |
435 | 421 |
436 return NGX_OK; | 422 return NGX_OK; |
437 } | |
438 | |
439 | |
440 static void | |
441 ngx_http_finalize_request_body(ngx_http_request_t *r, ngx_int_t rc) | |
442 { | |
443 if (r->request_body->temp_file | |
444 && r->request_body_in_persistent_file | |
445 && r->request_body_delete_incomplete_file) | |
446 { | |
447 if (ngx_delete_file(r->request_body->temp_file->file.name.data) | |
448 == NGX_FILE_ERROR) | |
449 { | |
450 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | |
451 ngx_delete_file_n " \"%s\" failed", | |
452 r->request_body->temp_file->file.name.data); | |
453 } | |
454 } | |
455 | |
456 ngx_http_finalize_request(r, rc); | |
457 } | 423 } |
458 | 424 |
459 | 425 |
460 ngx_int_t | 426 ngx_int_t |
461 ngx_http_discard_body(ngx_http_request_t *r) | 427 ngx_http_discard_body(ngx_http_request_t *r) |