Mercurial > hg > nginx
comparison src/http/ngx_http_request_body.c @ 1373:fdea12ffb24a
discard request body before going to keep-alive state and use lingering timeouts
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 07 Aug 2007 10:53:27 +0000 |
parents | cc114c85be0f |
children | 65dd057f71c7 |
comparison
equal
deleted
inserted
replaced
1372:2cc9b6651f75 | 1373:fdea12ffb24a |
---|---|
440 | 440 |
441 if (rev->timer_set) { | 441 if (rev->timer_set) { |
442 ngx_del_timer(rev); | 442 ngx_del_timer(rev); |
443 } | 443 } |
444 | 444 |
445 r->discard_body = 1; | |
446 | |
447 if (r->headers_in.content_length_n <= 0) { | 445 if (r->headers_in.content_length_n <= 0) { |
448 return NGX_OK; | 446 return NGX_OK; |
449 } | 447 } |
448 | |
449 r->discard_body = 1; | |
450 | 450 |
451 size = r->header_in->last - r->header_in->pos; | 451 size = r->header_in->last - r->header_in->pos; |
452 | 452 |
453 if (size) { | 453 if (size) { |
454 if (r->headers_in.content_length_n > size) { | 454 if (r->headers_in.content_length_n > size) { |
465 | 465 |
466 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 466 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
467 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 467 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
468 } | 468 } |
469 | 469 |
470 return ngx_http_read_discarded_request_body(r); | 470 (void) ngx_http_read_discarded_request_body(r); |
471 | |
472 return NGX_OK; | |
471 } | 473 } |
472 | 474 |
473 | 475 |
474 static void | 476 static void |
475 ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r) | 477 ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r) |
476 { | 478 { |
477 ngx_int_t rc; | 479 ngx_int_t rc; |
480 ngx_msec_t timer; | |
481 ngx_event_t *rev; | |
482 ngx_connection_t *c; | |
483 ngx_http_core_loc_conf_t *clcf; | |
484 | |
485 c = r->connection; | |
486 rev = c->read; | |
487 | |
488 if (rev->timedout) { | |
489 c->timedout = 1; | |
490 c->error = 1; | |
491 ngx_http_finalize_request(r, 0); | |
492 return; | |
493 } | |
494 | |
495 if (r->lingering_time) { | |
496 timer = r->lingering_time - ngx_time(); | |
497 | |
498 if (timer <= 0) { | |
499 r->discard_body = 0; | |
500 ngx_http_finalize_request(r, 0); | |
501 return; | |
502 } | |
503 | |
504 } else { | |
505 timer = 0; | |
506 } | |
478 | 507 |
479 rc = ngx_http_read_discarded_request_body(r); | 508 rc = ngx_http_read_discarded_request_body(r); |
480 | 509 |
481 if (rc == NGX_AGAIN) { | 510 if (rc == NGX_OK) { |
482 if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) { | 511 |
483 ngx_http_finalize_request(r, rc); | 512 r->discard_body = 0; |
484 return; | 513 |
485 } | 514 if (r->done) { |
486 } | 515 ngx_http_finalize_request(r, 0); |
487 | 516 } |
488 if (rc != NGX_OK) { | 517 |
518 return; | |
519 } | |
520 | |
521 /* rc == NGX_AGAIN */ | |
522 | |
523 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | |
489 ngx_http_finalize_request(r, rc); | 524 ngx_http_finalize_request(r, rc); |
525 return; | |
526 } | |
527 | |
528 if (timer) { | |
529 | |
530 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
531 | |
532 timer *= 1000; | |
533 | |
534 if (timer > clcf->lingering_timeout) { | |
535 timer = clcf->lingering_timeout; | |
536 } | |
537 | |
538 ngx_add_timer(rev, timer); | |
490 } | 539 } |
491 } | 540 } |
492 | 541 |
493 | 542 |
494 static ngx_int_t | 543 static ngx_int_t |
512 (size_t) r->headers_in.content_length_n; | 561 (size_t) r->headers_in.content_length_n; |
513 | 562 |
514 n = r->connection->recv(r->connection, buffer, size); | 563 n = r->connection->recv(r->connection, buffer, size); |
515 | 564 |
516 if (n == NGX_ERROR) { | 565 if (n == NGX_ERROR) { |
517 | |
518 r->connection->error = 1; | 566 r->connection->error = 1; |
519 | |
520 /* | |
521 * if a client request body is discarded then we already set | |
522 * some HTTP response code for client and we can ignore the error | |
523 */ | |
524 | |
525 return NGX_OK; | 567 return NGX_OK; |
526 } | 568 } |
527 | 569 |
528 if (n == NGX_AGAIN) { | 570 if (n == NGX_AGAIN) { |
529 return NGX_AGAIN; | 571 return NGX_AGAIN; |
531 | 573 |
532 r->headers_in.content_length_n -= n; | 574 r->headers_in.content_length_n -= n; |
533 | 575 |
534 } while (r->connection->read->ready); | 576 } while (r->connection->read->ready); |
535 | 577 |
536 return NGX_OK; | 578 return NGX_AGAIN; |
537 } | 579 } |