mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
HTTP/2: changed behavior of the "http2_max_field_size" directive.
Now it limits only the maximum length of literal string (either raw or compressed) in HPACK request header fields. It's easier to understand and to describe in the documentation.
This commit is contained in:
parent
edf30961e6
commit
090c471032
@ -1204,10 +1204,9 @@ static u_char *
|
|||||||
ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos,
|
ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||||
u_char *end)
|
u_char *end)
|
||||||
{
|
{
|
||||||
u_char ch;
|
u_char ch;
|
||||||
ngx_int_t value;
|
ngx_int_t value;
|
||||||
ngx_uint_t indexed, size_update, prefix;
|
ngx_uint_t indexed, size_update, prefix;
|
||||||
ngx_http_v2_srv_conf_t *h2scf;
|
|
||||||
|
|
||||||
if (end - pos < 1) {
|
if (end - pos < 1) {
|
||||||
return ngx_http_v2_state_save(h2c, pos, end,
|
return ngx_http_v2_state_save(h2c, pos, end,
|
||||||
@ -1288,20 +1287,11 @@ ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos,
|
|||||||
return ngx_http_v2_state_header_complete(h2c, pos, end);
|
return ngx_http_v2_state_header_complete(h2c, pos, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
|
|
||||||
ngx_http_v2_module);
|
|
||||||
|
|
||||||
h2c->state.field_limit = h2scf->max_field_size;
|
|
||||||
|
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
h2c->state.parse_name = 1;
|
h2c->state.parse_name = 1;
|
||||||
|
|
||||||
} else {
|
} else if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) {
|
||||||
if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) {
|
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
|
||||||
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
h2c->state.field_limit -= h2c->state.header.name.len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h2c->state.parse_value = 1;
|
h2c->state.parse_value = 1;
|
||||||
@ -1314,9 +1304,10 @@ static u_char *
|
|||||||
ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos,
|
ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos,
|
||||||
u_char *end)
|
u_char *end)
|
||||||
{
|
{
|
||||||
size_t alloc;
|
size_t alloc;
|
||||||
ngx_int_t len;
|
ngx_int_t len;
|
||||||
ngx_uint_t huff;
|
ngx_uint_t huff;
|
||||||
|
ngx_http_v2_srv_conf_t *h2scf;
|
||||||
|
|
||||||
if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)
|
if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)
|
||||||
&& h2c->state.length < NGX_HTTP_V2_INT_OCTETS)
|
&& h2c->state.length < NGX_HTTP_V2_INT_OCTETS)
|
||||||
@ -1363,14 +1354,16 @@ ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos,
|
|||||||
"http2 hpack %s string length: %i",
|
"http2 hpack %s string length: %i",
|
||||||
huff ? "encoded" : "raw", len);
|
huff ? "encoded" : "raw", len);
|
||||||
|
|
||||||
if ((size_t) len > h2c->state.field_limit) {
|
h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
|
||||||
|
ngx_http_v2_module);
|
||||||
|
|
||||||
|
if ((size_t) len > h2scf->max_field_size) {
|
||||||
ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
|
ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
|
||||||
"client exceeded http2_max_field_size limit");
|
"client exceeded http2_max_field_size limit");
|
||||||
|
|
||||||
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
|
return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
|
||||||
}
|
}
|
||||||
|
|
||||||
h2c->state.field_limit -= len;
|
|
||||||
h2c->state.field_rest = len;
|
h2c->state.field_rest = len;
|
||||||
|
|
||||||
if (h2c->state.stream == NULL && !h2c->state.index) {
|
if (h2c->state.stream == NULL && !h2c->state.index) {
|
||||||
|
@ -80,7 +80,6 @@ typedef struct {
|
|||||||
unsigned index:1;
|
unsigned index:1;
|
||||||
ngx_http_v2_header_t header;
|
ngx_http_v2_header_t header;
|
||||||
size_t header_limit;
|
size_t header_limit;
|
||||||
size_t field_limit;
|
|
||||||
u_char field_state;
|
u_char field_state;
|
||||||
u_char *field_start;
|
u_char *field_start;
|
||||||
u_char *field_end;
|
u_char *field_end;
|
||||||
|
Loading…
Reference in New Issue
Block a user