aboutsummaryrefslogtreecommitdiff
path: root/src/http/v2/ngx_http_v2_module.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2016-05-24 17:37:52 +0300
committerValentin Bartenev <vbart@nginx.com>2016-05-24 17:37:52 +0300
commit5429140c018726e8b28c724b06daaf0fe33d2205 (patch)
treea4472f68dd62a8f30acc7df95a450e5e9515b861 /src/http/v2/ngx_http_v2_module.c
parentadfd0b065cca23d2ca61ad43c5b8fdaa23957da9 (diff)
downloadnginx-5429140c018726e8b28c724b06daaf0fe33d2205.tar.gz
nginx-5429140c018726e8b28c724b06daaf0fe33d2205.zip
HTTP/2: implemented preread buffer for request body (closes #959).
Previously, the stream's window was kept zero in order to prevent a client from sending the request body before it was requested (see 887cca40ba6a for details). Until such initial window was acknowledged all requests with data were rejected (see 0aa07850922f for details). That approach revealed a number of problems: 1. Some clients (notably MS IE/Edge, Safari, iOS applications) show an error or even crash if a stream is rejected; 2. This requires at least one RTT for every request with body before the client receives window update and able to send data. To overcome these problems the new directive "http2_body_preread_size" is introduced. It sets the initial window and configures a special per stream preread buffer that is used to save all incoming data before the body is requested and processed. If the directive's value is lower than the default initial window (65535), as previously, all streams with data will be rejected until the new window is acknowledged. Otherwise, no special processing is used and all requests with data are welcome right from the connection start. The default value is chosen to be 64k, which is bigger than the default initial window. Setting it to zero is fully complaint to the previous behavior.
Diffstat (limited to 'src/http/v2/ngx_http_v2_module.c')
-rw-r--r--src/http/v2/ngx_http_v2_module.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/http/v2/ngx_http_v2_module.c b/src/http/v2/ngx_http_v2_module.c
index 5a4561c2b..b7d99e055 100644
--- a/src/http/v2/ngx_http_v2_module.c
+++ b/src/http/v2/ngx_http_v2_module.c
@@ -30,6 +30,7 @@ static char *ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, void *parent,
static char *ngx_http_v2_recv_buffer_size(ngx_conf_t *cf, void *post,
void *data);
static char *ngx_http_v2_pool_size(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_v2_preread_size(ngx_conf_t *cf, void *post, void *data);
static char *ngx_http_v2_streams_index_mask(ngx_conf_t *cf, void *post,
void *data);
static char *ngx_http_v2_chunk_size(ngx_conf_t *cf, void *post, void *data);
@@ -41,6 +42,8 @@ static ngx_conf_post_t ngx_http_v2_recv_buffer_size_post =
{ ngx_http_v2_recv_buffer_size };
static ngx_conf_post_t ngx_http_v2_pool_size_post =
{ ngx_http_v2_pool_size };
+static ngx_conf_post_t ngx_http_v2_preread_size_post =
+ { ngx_http_v2_preread_size };
static ngx_conf_post_t ngx_http_v2_streams_index_mask_post =
{ ngx_http_v2_streams_index_mask };
static ngx_conf_post_t ngx_http_v2_chunk_size_post =
@@ -84,6 +87,13 @@ static ngx_command_t ngx_http_v2_commands[] = {
offsetof(ngx_http_v2_srv_conf_t, max_header_size),
NULL },
+ { ngx_string("http2_body_preread_size"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_size_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_v2_srv_conf_t, preread_size),
+ &ngx_http_v2_preread_size_post },
+
{ ngx_string("http2_streams_index_size"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
@@ -316,6 +326,8 @@ ngx_http_v2_create_srv_conf(ngx_conf_t *cf)
h2scf->max_field_size = NGX_CONF_UNSET_SIZE;
h2scf->max_header_size = NGX_CONF_UNSET_SIZE;
+ h2scf->preread_size = NGX_CONF_UNSET_SIZE;
+
h2scf->streams_index_mask = NGX_CONF_UNSET_UINT;
h2scf->recv_timeout = NGX_CONF_UNSET_MSEC;
@@ -341,6 +353,8 @@ ngx_http_v2_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->max_header_size, prev->max_header_size,
16384);
+ ngx_conf_merge_size_value(conf->preread_size, prev->preread_size, 65536);
+
ngx_conf_merge_uint_value(conf->streams_index_mask,
prev->streams_index_mask, 32 - 1);
@@ -420,6 +434,23 @@ ngx_http_v2_pool_size(ngx_conf_t *cf, void *post, void *data)
static char *
+ngx_http_v2_preread_size(ngx_conf_t *cf, void *post, void *data)
+{
+ size_t *sp = data;
+
+ if (*sp > NGX_HTTP_V2_MAX_WINDOW) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "the maximum body preread buffer size is %uz",
+ NGX_HTTP_V2_MAX_WINDOW);
+
+ return NGX_CONF_ERROR;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static char *
ngx_http_v2_streams_index_mask(ngx_conf_t *cf, void *post, void *data)
{
ngx_uint_t *np = data;