Welcome! Log In Create A New Profile

Advanced

[nginx] HTTP/2: reduced difference to HTTP/1.x in reading request body.

Valentin Bartenev
April 24, 2017 07:22AM
details: http://hg.nginx.org/nginx/rev/2c4dbcd6f2e4
branches:
changeset: 6989:2c4dbcd6f2e4
user: Valentin Bartenev <vbart@nginx.com>
date: Mon Apr 24 14:17:13 2017 +0300
description:
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.

diffstat:

src/http/ngx_http_request_body.c | 20 ++++++++++++--------
src/http/v2/ngx_http_v2.c | 28 +++++-----------------------
src/http/v2/ngx_http_v2.h | 3 +--
3 files changed, 18 insertions(+), 33 deletions(-)

diffs (115 lines):

diff -r cc823122d50d -r 2c4dbcd6f2e4 src/http/ngx_http_request_body.c
--- a/src/http/ngx_http_request_body.c Mon Apr 24 14:16:57 2017 +0300
+++ b/src/http/ngx_http_request_body.c Mon Apr 24 14:17:13 2017 +0300
@@ -46,13 +46,6 @@ ngx_http_read_client_request_body(ngx_ht
return NGX_OK;
}

-#if (NGX_HTTP_V2)
- if (r->stream) {
- rc = ngx_http_v2_read_request_body(r, post_handler);
- goto done;
- }
-#endif
-
if (ngx_http_test_expect(r) != NGX_OK) {
rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
goto done;
@@ -85,6 +78,13 @@ ngx_http_read_client_request_body(ngx_ht
return NGX_OK;
}

+#if (NGX_HTTP_V2)
+ if (r->stream) {
+ rc = ngx_http_v2_read_request_body(r);
+ goto done;
+ }
+#endif
+
preread = r->header_in->last - r->header_in->pos;

if (preread) {
@@ -805,7 +805,11 @@ ngx_http_test_expect(ngx_http_request_t

if (r->expect_tested
|| r->headers_in.expect == NULL
- || r->http_version < NGX_HTTP_VERSION_11)
+ || r->http_version < NGX_HTTP_VERSION_11
+#if (NGX_HTTP_V2)
+ || r->stream != NULL
+#endif
+ )
{
return NGX_OK;
}
diff -r cc823122d50d -r 2c4dbcd6f2e4 src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c Mon Apr 24 14:16:57 2017 +0300
+++ b/src/http/v2/ngx_http_v2.c Mon Apr 24 14:17:13 2017 +0300
@@ -3522,8 +3522,7 @@ ngx_http_v2_run_request(ngx_http_request


ngx_int_t
-ngx_http_v2_read_request_body(ngx_http_request_t *r,
- ngx_http_client_body_handler_pt post_handler)
+ngx_http_v2_read_request_body(ngx_http_request_t *r)
{
off_t len;
size_t size;
@@ -3536,33 +3535,14 @@ ngx_http_v2_read_request_body(ngx_http_r
ngx_http_v2_connection_t *h2c;

stream = r->stream;
+ rb = r->request_body;

if (stream->skip_data) {
r->request_body_no_buffering = 0;
- post_handler(r);
+ rb->post_handler(r);
return NGX_OK;
}

- rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
- if (rb == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- /*
- * set by ngx_pcalloc():
- *
- * rb->bufs = NULL;
- * rb->buf = NULL;
- * rb->received = 0;
- * rb->free = NULL;
- * rb->busy = NULL;
- */
-
- rb->rest = 1;
- rb->post_handler = post_handler;
-
- r->request_body = rb;
-
h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

@@ -3612,6 +3592,8 @@ ngx_http_v2_read_request_body(ngx_http_r
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

+ rb->rest = 1;
+
buf = stream->preread;

if (stream->in_closed) {
diff -r cc823122d50d -r 2c4dbcd6f2e4 src/http/v2/ngx_http_v2.h
--- a/src/http/v2/ngx_http_v2.h Mon Apr 24 14:16:57 2017 +0300
+++ b/src/http/v2/ngx_http_v2.h Mon Apr 24 14:17:13 2017 +0300
@@ -264,8 +264,7 @@ ngx_http_v2_queue_blocked_frame(ngx_http
void ngx_http_v2_init(ngx_event_t *rev);
void ngx_http_v2_request_headers_init(void);

-ngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r,
- ngx_http_client_body_handler_pt post_handler);
+ngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r);
ngx_int_t ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r);

void ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] HTTP/2: reduced difference to HTTP/1.x in reading request body.

Valentin Bartenev 365 April 24, 2017 07:22AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 198
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready