HTTP/2: close connection on frames with self-dependency.
Don't waste server resources by sending RST_STREAM frames. Instead,
reject HEADERS and PRIORITY frames with self-dependency by closing
connection with PROTOCOL_ERROR.
Ruslan Ermilov
2 years ago
1106 | 1106 | return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | h2c->last_sid = h2c->state.sid; | |
1110 | ||
1111 | h2c->state.pool = ngx_create_pool(1024, h2c->connection->log); | |
1112 | if (h2c->state.pool == NULL) { | |
1113 | return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); | |
1114 | } | |
1115 | ||
1116 | 1109 | if (depend == h2c->state.sid) { |
1117 | 1110 | ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, |
1118 | 1111 | "client sent HEADERS frame for stream %ui " |
1119 | 1112 | "with incorrect dependency", h2c->state.sid); |
1120 | 1113 | |
1121 | status = NGX_HTTP_V2_PROTOCOL_ERROR; | |
1122 | goto rst_stream; | |
1114 | return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); | |
1115 | } | |
1116 | ||
1117 | h2c->last_sid = h2c->state.sid; | |
1118 | ||
1119 | h2c->state.pool = ngx_create_pool(1024, h2c->connection->log); | |
1120 | if (h2c->state.pool == NULL) { | |
1121 | return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR); | |
1123 | 1122 | } |
1124 | 1123 | |
1125 | 1124 | h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx, |
1848 | 1847 | "client sent PRIORITY frame for stream %ui " |
1849 | 1848 | "with incorrect dependency", h2c->state.sid); |
1850 | 1849 | |
1851 | node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0); | |
1852 | ||
1853 | if (node && node->stream) { | |
1854 | if (ngx_http_v2_terminate_stream(h2c, node->stream, | |
1855 | NGX_HTTP_V2_PROTOCOL_ERROR) | |
1856 | == NGX_ERROR) | |
1857 | { | |
1858 | return ngx_http_v2_connection_error(h2c, | |
1859 | NGX_HTTP_V2_INTERNAL_ERROR); | |
1860 | } | |
1861 | ||
1862 | } else { | |
1863 | if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid, | |
1864 | NGX_HTTP_V2_PROTOCOL_ERROR) | |
1865 | == NGX_ERROR) | |
1866 | { | |
1867 | return ngx_http_v2_connection_error(h2c, | |
1868 | NGX_HTTP_V2_INTERNAL_ERROR); | |
1869 | } | |
1870 | } | |
1871 | ||
1872 | return ngx_http_v2_state_complete(h2c, pos, end); | |
1850 | return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR); | |
1873 | 1851 | } |
1874 | 1852 | |
1875 | 1853 | node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1); |