]> git.kaiwu.me - nginx.git/commitdiff
HTTP/2: refuse streams with data until SETTINGS is acknowledged.
authorValentin Bartenev <vbart@nginx.com>
Thu, 14 Apr 2016 12:14:15 +0000 (15:14 +0300)
committerValentin Bartenev <vbart@nginx.com>
Thu, 14 Apr 2016 12:14:15 +0000 (15:14 +0300)
A client is allowed to send requests before receiving and acknowledging
the SETTINGS frame.  Such a client having a wrong idea about the stream's
could send the request body that nginx isn't ready to process.

The previous behavior was to send RST_STREAM with FLOW_CONTROL_ERROR in
such case, but it didn't allow retrying requests that have been rejected.

src/http/v2/ngx_http_v2.c
src/http/v2/ngx_http_v2.h

index a2070758f8ded2f7159e38a77c8f6e188d54de10..74754977b661340708a8da530a9d5aad2dce1b42 100644 (file)
@@ -1058,6 +1058,12 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
         goto rst_stream;
     }
 
+    if (!h2c->settings_ack && !(h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG))
+    {
+        status = NGX_HTTP_V2_REFUSED_STREAM;
+        goto rst_stream;
+    }
+
     node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1);
 
     if (node == NULL) {
@@ -1878,7 +1884,7 @@ ngx_http_v2_state_settings(ngx_http_v2_connection_t *h2c, u_char *pos,
             return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
         }
 
-        /* TODO settings acknowledged */
+        h2c->settings_ack = 1;
 
         return ngx_http_v2_state_complete(h2c, pos, end);
     }
index 7a77c27b3b525f566e9037657465be8c8cffb2d2..1adf8deb92f3c0d310b1e1b6a08a033bc12fce96 100644 (file)
@@ -141,6 +141,7 @@ struct ngx_http_v2_connection_s {
     ngx_uint_t                       last_sid;
 
     unsigned                         closed_nodes:8;
+    unsigned                         settings_ack:1;
     unsigned                         blocked:1;
 };