comparison src/http/ngx_http_request_body.c @ 6420:3b9fe734a76c

Request body: moved handling of the last part in the save filter. No functional changes.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 01 Mar 2016 15:18:07 +0300
parents 02abce4764b7
children 887cca40ba6a
comparison
equal deleted inserted replaced
6419:39a806ccf21e 6420:3b9fe734a76c
32 { 32 {
33 size_t preread; 33 size_t preread;
34 ssize_t size; 34 ssize_t size;
35 ngx_int_t rc; 35 ngx_int_t rc;
36 ngx_buf_t *b; 36 ngx_buf_t *b;
37 ngx_chain_t out, *cl; 37 ngx_chain_t out;
38 ngx_http_request_body_t *rb; 38 ngx_http_request_body_t *rb;
39 ngx_http_core_loc_conf_t *clcf; 39 ngx_http_core_loc_conf_t *clcf;
40 40
41 r->main->count++; 41 r->main->count++;
42 42
55 } 55 }
56 56
57 if (ngx_http_test_expect(r) != NGX_OK) { 57 if (ngx_http_test_expect(r) != NGX_OK) {
58 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; 58 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
59 goto done; 59 goto done;
60 }
61
62 if (r->request_body_no_buffering) {
63 r->request_body_in_file_only = 0;
64 } 60 }
65 61
66 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); 62 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
67 if (rb == NULL) { 63 if (rb == NULL) {
68 rc = NGX_HTTP_INTERNAL_SERVER_ERROR; 64 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
146 } 142 }
147 } 143 }
148 144
149 if (rb->rest == 0) { 145 if (rb->rest == 0) {
150 /* the whole request body was pre-read */ 146 /* the whole request body was pre-read */
151
152 if (r->request_body_in_file_only) {
153 if (ngx_http_write_request_body(r) != NGX_OK) {
154 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
155 goto done;
156 }
157
158 if (rb->temp_file->file.offset != 0) {
159
160 cl = ngx_chain_get_free_buf(r->pool, &rb->free);
161 if (cl == NULL) {
162 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
163 goto done;
164 }
165
166 b = cl->buf;
167
168 ngx_memzero(b, sizeof(ngx_buf_t));
169
170 b->in_file = 1;
171 b->file_last = rb->temp_file->file.offset;
172 b->file = &rb->temp_file->file;
173
174 rb->bufs = cl;
175 }
176 }
177
178 r->request_body_no_buffering = 0; 147 r->request_body_no_buffering = 0;
179
180 post_handler(r); 148 post_handler(r);
181
182 return NGX_OK; 149 return NGX_OK;
183 } 150 }
184 151
185 if (rb->rest < 0) { 152 if (rb->rest < 0) {
186 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, 153 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
287 { 254 {
288 off_t rest; 255 off_t rest;
289 size_t size; 256 size_t size;
290 ssize_t n; 257 ssize_t n;
291 ngx_int_t rc; 258 ngx_int_t rc;
292 ngx_buf_t *b; 259 ngx_chain_t out;
293 ngx_chain_t *cl, out;
294 ngx_connection_t *c; 260 ngx_connection_t *c;
295 ngx_http_request_body_t *rb; 261 ngx_http_request_body_t *rb;
296 ngx_http_core_loc_conf_t *clcf; 262 ngx_http_core_loc_conf_t *clcf;
297 263
298 c = r->connection; 264 c = r->connection;
435 } 401 }
436 } 402 }
437 403
438 if (c->read->timer_set) { 404 if (c->read->timer_set) {
439 ngx_del_timer(c->read); 405 ngx_del_timer(c->read);
440 }
441
442 if (rb->temp_file || r->request_body_in_file_only) {
443
444 /* save the last part */
445
446 if (ngx_http_write_request_body(r) != NGX_OK) {
447 return NGX_HTTP_INTERNAL_SERVER_ERROR;
448 }
449
450 if (rb->temp_file->file.offset != 0) {
451
452 cl = ngx_chain_get_free_buf(r->pool, &rb->free);
453 if (cl == NULL) {
454 return NGX_HTTP_INTERNAL_SERVER_ERROR;
455 }
456
457 b = cl->buf;
458
459 ngx_memzero(b, sizeof(ngx_buf_t));
460
461 b->in_file = 1;
462 b->file_last = rb->temp_file->file.offset;
463 b->file = &rb->temp_file->file;
464
465 rb->bufs = cl;
466 }
467 } 406 }
468 407
469 if (!r->request_body_no_buffering) { 408 if (!r->request_body_no_buffering) {
470 r->read_event_handler = ngx_http_block_reading; 409 r->read_event_handler = ngx_http_block_reading;
471 rb->post_handler(r); 410 rb->post_handler(r);
1125 1064
1126 1065
1127 ngx_int_t 1066 ngx_int_t
1128 ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in) 1067 ngx_http_request_body_save_filter(ngx_http_request_t *r, ngx_chain_t *in)
1129 { 1068 {
1130 #if (NGX_DEBUG) 1069 ngx_buf_t *b;
1131 ngx_chain_t *cl; 1070 ngx_chain_t *cl;
1132 #endif
1133 ngx_http_request_body_t *rb; 1071 ngx_http_request_body_t *rb;
1134 1072
1135 rb = r->request_body; 1073 rb = r->request_body;
1136 1074
1137 #if (NGX_DEBUG) 1075 #if (NGX_DEBUG)
1164 1102
1165 if (ngx_chain_add_copy(r->pool, &rb->bufs, in) != NGX_OK) { 1103 if (ngx_chain_add_copy(r->pool, &rb->bufs, in) != NGX_OK) {
1166 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1104 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1167 } 1105 }
1168 1106
1169 if (rb->rest > 0 1107 if (r->request_body_no_buffering) {
1170 && rb->buf && rb->buf->last == rb->buf->end 1108 return NGX_OK;
1171 && !r->request_body_no_buffering) 1109 }
1172 { 1110
1111 if (rb->rest > 0) {
1112
1113 if (rb->buf && rb->buf->last == rb->buf->end
1114 && ngx_http_write_request_body(r) != NGX_OK)
1115 {
1116 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1117 }
1118
1119 return NGX_OK;
1120 }
1121
1122 /* rb->rest == 0 */
1123
1124 if (rb->temp_file || r->request_body_in_file_only) {
1125
1173 if (ngx_http_write_request_body(r) != NGX_OK) { 1126 if (ngx_http_write_request_body(r) != NGX_OK) {
1174 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1127 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1175 } 1128 }
1129
1130 if (rb->temp_file->file.offset != 0) {
1131
1132 cl = ngx_chain_get_free_buf(r->pool, &rb->free);
1133 if (cl == NULL) {
1134 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1135 }
1136
1137 b = cl->buf;
1138
1139 ngx_memzero(b, sizeof(ngx_buf_t));
1140
1141 b->in_file = 1;
1142 b->file_last = rb->temp_file->file.offset;
1143 b->file = &rb->temp_file->file;
1144
1145 rb->bufs = cl;
1146 }
1176 } 1147 }
1177 1148
1178 return NGX_OK; 1149 return NGX_OK;
1179 } 1150 }