comparison src/http/ngx_http_request_body.c @ 578:f3a9e57d2e17

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 11 Mar 2010 21:27:17 +0300
parents 1dcf6adad484
children
comparison
equal deleted inserted replaced
539:5f4de8cf0d9d 578:f3a9e57d2e17
11 11
12 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r); 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); 13 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r);
14 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r, 14 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r,
15 ngx_chain_t *body); 15 ngx_chain_t *body);
16 static void ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r);
17 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r); 16 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r);
18 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r); 17 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r);
19 18
20 19
21 /* 20 /*
458 457
459 size = r->header_in->last - r->header_in->pos; 458 size = r->header_in->last - r->header_in->pos;
460 459
461 if (size) { 460 if (size) {
462 if (r->headers_in.content_length_n > size) { 461 if (r->headers_in.content_length_n > size) {
462 r->header_in->pos += size;
463 r->headers_in.content_length_n -= size; 463 r->headers_in.content_length_n -= size;
464 464
465 } else { 465 } else {
466 r->header_in->pos += (size_t) r->headers_in.content_length_n; 466 r->header_in->pos += (size_t) r->headers_in.content_length_n;
467 r->headers_in.content_length_n = 0; 467 r->headers_in.content_length_n = 0;
468 return NGX_OK; 468 return NGX_OK;
469 } 469 }
470 } 470 }
471 471
472 r->discard_body = 1; 472 r->read_event_handler = ngx_http_discarded_request_body_handler;
473
474 r->read_event_handler = ngx_http_read_discarded_request_body_handler;
475 473
476 if (ngx_handle_read_event(rev, 0) != NGX_OK) { 474 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
477 return NGX_HTTP_INTERNAL_SERVER_ERROR; 475 return NGX_HTTP_INTERNAL_SERVER_ERROR;
478 } 476 }
479 477
480 r->count++; 478 if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
481 (void) ngx_http_read_discarded_request_body(r); 479 r->lingering_close = 0;
480
481 } else {
482 r->count++;
483 r->discard_body = 1;
484 }
482 485
483 return NGX_OK; 486 return NGX_OK;
484 } 487 }
485 488
486 489
487 static void 490 void
488 ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r) 491 ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
489 { 492 {
490 ngx_int_t rc; 493 ngx_int_t rc;
491 ngx_msec_t timer; 494 ngx_msec_t timer;
492 ngx_event_t *rev; 495 ngx_event_t *rev;
493 ngx_connection_t *c; 496 ngx_connection_t *c;
497 rev = c->read; 500 rev = c->read;
498 501
499 if (rev->timedout) { 502 if (rev->timedout) {
500 c->timedout = 1; 503 c->timedout = 1;
501 c->error = 1; 504 c->error = 1;
502 ngx_http_finalize_request(r, 0); 505 ngx_http_finalize_request(r, NGX_ERROR);
503 return; 506 return;
504 } 507 }
505 508
506 if (r->lingering_time) { 509 if (r->lingering_time) {
507 timer = (ngx_msec_t) (r->lingering_time - ngx_time()); 510 timer = (ngx_msec_t) (r->lingering_time - ngx_time());
508 511
509 if (timer <= 0) { 512 if (timer <= 0) {
510 r->discard_body = 0; 513 r->discard_body = 0;
511 ngx_http_finalize_request(r, 0); 514 r->lingering_close = 0;
515 ngx_http_finalize_request(r, NGX_ERROR);
512 return; 516 return;
513 } 517 }
514 518
515 } else { 519 } else {
516 timer = 0; 520 timer = 0;
517 } 521 }
518 522
519 rc = ngx_http_read_discarded_request_body(r); 523 rc = ngx_http_read_discarded_request_body(r);
520 524
521 if (rc == NGX_OK) { 525 if (rc == NGX_OK) {
522
523 r->discard_body = 0; 526 r->discard_body = 0;
524 527 r->lingering_close = 0;
525 if (r->done) { 528 ngx_http_finalize_request(r, NGX_DONE);
526 ngx_http_finalize_request(r, 0);
527 }
528
529 return; 529 return;
530 } 530 }
531 531
532 /* rc == NGX_AGAIN */ 532 /* rc == NGX_AGAIN */
533 533
534 if (ngx_handle_read_event(rev, 0) != NGX_OK) { 534 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
535 c->error = 1; 535 c->error = 1;
536 ngx_http_finalize_request(r, rc); 536 ngx_http_finalize_request(r, NGX_ERROR);
537 return; 537 return;
538 } 538 }
539 539
540 if (timer) { 540 if (timer) {
541 541
560 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE]; 560 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
561 561
562 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 562 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
563 "http read discarded body"); 563 "http read discarded body");
564 564
565 do { 565 for ( ;; ) {
566 if (r->headers_in.content_length_n == 0) { 566 if (r->headers_in.content_length_n == 0) {
567 r->read_event_handler = ngx_http_block_reading; 567 r->read_event_handler = ngx_http_block_reading;
568 return NGX_OK; 568 return NGX_OK;
569 } 569 }
570 570
571 if (!r->connection->read->ready) {
572 return NGX_AGAIN;
573 }
574
571 size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ? 575 size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ?
572 NGX_HTTP_DISCARD_BUFFER_SIZE: 576 NGX_HTTP_DISCARD_BUFFER_SIZE:
573 (size_t) r->headers_in.content_length_n; 577 (size_t) r->headers_in.content_length_n;
574 578
575 n = r->connection->recv(r->connection, buffer, size); 579 n = r->connection->recv(r->connection, buffer, size);
586 if (n == 0) { 590 if (n == 0) {
587 return NGX_OK; 591 return NGX_OK;
588 } 592 }
589 593
590 r->headers_in.content_length_n -= n; 594 r->headers_in.content_length_n -= n;
591 595 }
592 } while (r->connection->read->ready);
593
594 return NGX_AGAIN;
595 } 596 }
596 597
597 598
598 static ngx_int_t 599 static ngx_int_t
599 ngx_http_test_expect(ngx_http_request_t *r) 600 ngx_http_test_expect(ngx_http_request_t *r)