comparison src/http/ngx_http_request_body.c @ 4922:dfa586842962

Request body: code duplication reduced, no functional changes. The r->request_body_in_file_only with empty body case is now handled in ngx_http_write_request_body().
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 21 Nov 2012 00:55:50 +0000
parents 834049edae24
children 57174af2e695
comparison
equal deleted inserted replaced
4921:fbc0791bebb2 4922:dfa586842962
31 { 31 {
32 size_t preread; 32 size_t preread;
33 ssize_t size; 33 ssize_t size;
34 ngx_buf_t *b; 34 ngx_buf_t *b;
35 ngx_chain_t *cl, **next; 35 ngx_chain_t *cl, **next;
36 ngx_temp_file_t *tf;
37 ngx_http_request_body_t *rb; 36 ngx_http_request_body_t *rb;
38 ngx_http_core_loc_conf_t *clcf; 37 ngx_http_core_loc_conf_t *clcf;
39 38
40 r->main->count++; 39 r->main->count++;
41 40
63 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 62 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
64 63
65 if (r->headers_in.content_length_n == 0) { 64 if (r->headers_in.content_length_n == 0) {
66 65
67 if (r->request_body_in_file_only) { 66 if (r->request_body_in_file_only) {
68 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)); 67 if (ngx_http_write_request_body(r, NULL) != NGX_OK) {
69 if (tf == NULL) {
70 return NGX_HTTP_INTERNAL_SERVER_ERROR;
71 }
72
73 tf->file.fd = NGX_INVALID_FILE;
74 tf->file.log = r->connection->log;
75 tf->path = clcf->client_body_temp_path;
76 tf->pool = r->pool;
77 tf->warn = "a client request body is buffered to a temporary file";
78 tf->log_level = r->request_body_file_log_level;
79 tf->persistent = r->request_body_in_persistent_file;
80 tf->clean = r->request_body_in_clean_file;
81
82 if (r->request_body_file_group_access) {
83 tf->access = 0660;
84 }
85
86 rb->temp_file = tf;
87
88 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
89 tf->persistent, tf->clean, tf->access)
90 != NGX_OK)
91 {
92 return NGX_HTTP_INTERNAL_SERVER_ERROR; 68 return NGX_HTTP_INTERNAL_SERVER_ERROR;
93 } 69 }
94 } 70 }
95 71
96 post_handler(r); 72 post_handler(r);
417 if (r->request_body_file_group_access) { 393 if (r->request_body_file_group_access) {
418 tf->access = 0660; 394 tf->access = 0660;
419 } 395 }
420 396
421 rb->temp_file = tf; 397 rb->temp_file = tf;
398
399 if (body == NULL) {
400 /* empty body with r->request_body_in_file_only */
401
402 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
403 tf->persistent, tf->clean, tf->access)
404 != NGX_OK)
405 {
406 return NGX_ERROR;
407 }
408
409 return NGX_OK;
410 }
422 } 411 }
423 412
424 n = ngx_write_chain_to_temp_file(rb->temp_file, body); 413 n = ngx_write_chain_to_temp_file(rb->temp_file, body);
425 414
426 /* TODO: n == 0 or not complete and level event */ 415 /* TODO: n == 0 or not complete and level event */