Mercurial > hg > nginx
comparison src/http/v2/ngx_http_v2.c @ 6989:2c4dbcd6f2e4
HTTP/2: reduced difference to HTTP/1.x in reading request body.
Particularly, this eliminates difference in behavior for requests without body
and deduplicates code.
Prodded by Piotr Sikora.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 24 Apr 2017 14:17:13 +0300 |
parents | cc823122d50d |
children | ed1101bbf19f |
comparison
equal
deleted
inserted
replaced
6988:cc823122d50d | 6989:2c4dbcd6f2e4 |
---|---|
3520 ngx_http_process_request(r); | 3520 ngx_http_process_request(r); |
3521 } | 3521 } |
3522 | 3522 |
3523 | 3523 |
3524 ngx_int_t | 3524 ngx_int_t |
3525 ngx_http_v2_read_request_body(ngx_http_request_t *r, | 3525 ngx_http_v2_read_request_body(ngx_http_request_t *r) |
3526 ngx_http_client_body_handler_pt post_handler) | |
3527 { | 3526 { |
3528 off_t len; | 3527 off_t len; |
3529 size_t size; | 3528 size_t size; |
3530 ngx_buf_t *buf; | 3529 ngx_buf_t *buf; |
3531 ngx_int_t rc; | 3530 ngx_int_t rc; |
3534 ngx_http_request_body_t *rb; | 3533 ngx_http_request_body_t *rb; |
3535 ngx_http_core_loc_conf_t *clcf; | 3534 ngx_http_core_loc_conf_t *clcf; |
3536 ngx_http_v2_connection_t *h2c; | 3535 ngx_http_v2_connection_t *h2c; |
3537 | 3536 |
3538 stream = r->stream; | 3537 stream = r->stream; |
3538 rb = r->request_body; | |
3539 | 3539 |
3540 if (stream->skip_data) { | 3540 if (stream->skip_data) { |
3541 r->request_body_no_buffering = 0; | 3541 r->request_body_no_buffering = 0; |
3542 post_handler(r); | 3542 rb->post_handler(r); |
3543 return NGX_OK; | 3543 return NGX_OK; |
3544 } | 3544 } |
3545 | |
3546 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)); | |
3547 if (rb == NULL) { | |
3548 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
3549 } | |
3550 | |
3551 /* | |
3552 * set by ngx_pcalloc(): | |
3553 * | |
3554 * rb->bufs = NULL; | |
3555 * rb->buf = NULL; | |
3556 * rb->received = 0; | |
3557 * rb->free = NULL; | |
3558 * rb->busy = NULL; | |
3559 */ | |
3560 | |
3561 rb->rest = 1; | |
3562 rb->post_handler = post_handler; | |
3563 | |
3564 r->request_body = rb; | |
3565 | 3545 |
3566 h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module); | 3546 h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module); |
3567 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 3547 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
3568 | 3548 |
3569 len = r->headers_in.content_length_n; | 3549 len = r->headers_in.content_length_n; |
3609 | 3589 |
3610 if (rb->buf == NULL) { | 3590 if (rb->buf == NULL) { |
3611 stream->skip_data = 1; | 3591 stream->skip_data = 1; |
3612 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 3592 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
3613 } | 3593 } |
3594 | |
3595 rb->rest = 1; | |
3614 | 3596 |
3615 buf = stream->preread; | 3597 buf = stream->preread; |
3616 | 3598 |
3617 if (stream->in_closed) { | 3599 if (stream->in_closed) { |
3618 r->request_body_no_buffering = 0; | 3600 r->request_body_no_buffering = 0; |