discard request body in cycle
Igor Sysoev
13 years ago
500 | 500 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
501 | 501 | "http read discarded body"); |
502 | 502 | |
503 | if (r->headers_in.content_length_n == 0) { | |
504 | return NGX_OK; | |
505 | } | |
506 | ||
507 | size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ? | |
508 | NGX_HTTP_DISCARD_BUFFER_SIZE: | |
509 | (size_t) r->headers_in.content_length_n; | |
510 | ||
511 | n = r->connection->recv(r->connection, buffer, size); | |
512 | ||
513 | if (n == NGX_ERROR) { | |
514 | ||
515 | r->connection->error = 1; | |
516 | ||
517 | /* | |
518 | * if a client request body is discarded then we already set | |
519 | * some HTTP response code for client and we can ignore the error | |
520 | */ | |
521 | ||
522 | return NGX_OK; | |
523 | } | |
524 | ||
525 | if (n == NGX_AGAIN) { | |
526 | return NGX_AGAIN; | |
527 | } | |
528 | ||
529 | r->headers_in.content_length_n -= n; | |
503 | do { | |
504 | if (r->headers_in.content_length_n == 0) { | |
505 | return NGX_OK; | |
506 | } | |
507 | ||
508 | size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ? | |
509 | NGX_HTTP_DISCARD_BUFFER_SIZE: | |
510 | (size_t) r->headers_in.content_length_n; | |
511 | ||
512 | n = r->connection->recv(r->connection, buffer, size); | |
513 | ||
514 | if (n == NGX_ERROR) { | |
515 | ||
516 | r->connection->error = 1; | |
517 | ||
518 | /* | |
519 | * if a client request body is discarded then we already set | |
520 | * some HTTP response code for client and we can ignore the error | |
521 | */ | |
522 | ||
523 | return NGX_OK; | |
524 | } | |
525 | ||
526 | if (n == NGX_AGAIN) { | |
527 | return NGX_AGAIN; | |
528 | } | |
529 | ||
530 | r->headers_in.content_length_n -= n; | |
531 | ||
532 | } while (r->connection->read->ready); | |
530 | 533 | |
531 | 534 | return NGX_OK; |
532 | 535 | } |