comparison src/http/v2/ngx_http_v2.c @ 6285:1f26bf65b1bc

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.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 27 Oct 2015 23:16:35 +0300
parents 66ee1c5cb6aa
children 0f4b7800e681
comparison
equal deleted inserted replaced
6284:66ee1c5cb6aa 6285:1f26bf65b1bc
1202 1202
1203 static u_char * 1203 static u_char *
1204 ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos, 1204 ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos,
1205 u_char *end) 1205 u_char *end)
1206 { 1206 {
1207 u_char ch; 1207 u_char ch;
1208 ngx_int_t value; 1208 ngx_int_t value;
1209 ngx_uint_t indexed, size_update, prefix; 1209 ngx_uint_t indexed, size_update, prefix;
1210 ngx_http_v2_srv_conf_t *h2scf;
1211 1210
1212 if (end - pos < 1) { 1211 if (end - pos < 1) {
1213 return ngx_http_v2_state_save(h2c, pos, end, 1212 return ngx_http_v2_state_save(h2c, pos, end,
1214 ngx_http_v2_state_header_block); 1213 ngx_http_v2_state_header_block);
1215 } 1214 }
1286 } 1285 }
1287 1286
1288 return ngx_http_v2_state_header_complete(h2c, pos, end); 1287 return ngx_http_v2_state_header_complete(h2c, pos, end);
1289 } 1288 }
1290 1289
1291 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
1292 ngx_http_v2_module);
1293
1294 h2c->state.field_limit = h2scf->max_field_size;
1295
1296 if (value == 0) { 1290 if (value == 0) {
1297 h2c->state.parse_name = 1; 1291 h2c->state.parse_name = 1;
1298 1292
1299 } else { 1293 } else if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) {
1300 if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) { 1294 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
1301 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
1302 }
1303
1304 h2c->state.field_limit -= h2c->state.header.name.len;
1305 } 1295 }
1306 1296
1307 h2c->state.parse_value = 1; 1297 h2c->state.parse_value = 1;
1308 1298
1309 return ngx_http_v2_state_field_len(h2c, pos, end); 1299 return ngx_http_v2_state_field_len(h2c, pos, end);
1312 1302
1313 static u_char * 1303 static u_char *
1314 ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos, 1304 ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos,
1315 u_char *end) 1305 u_char *end)
1316 { 1306 {
1317 size_t alloc; 1307 size_t alloc;
1318 ngx_int_t len; 1308 ngx_int_t len;
1319 ngx_uint_t huff; 1309 ngx_uint_t huff;
1310 ngx_http_v2_srv_conf_t *h2scf;
1320 1311
1321 if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) 1312 if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)
1322 && h2c->state.length < NGX_HTTP_V2_INT_OCTETS) 1313 && h2c->state.length < NGX_HTTP_V2_INT_OCTETS)
1323 { 1314 {
1324 return ngx_http_v2_handle_continuation(h2c, pos, end, 1315 return ngx_http_v2_handle_continuation(h2c, pos, end,
1361 1352
1362 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, 1353 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
1363 "http2 hpack %s string length: %i", 1354 "http2 hpack %s string length: %i",
1364 huff ? "encoded" : "raw", len); 1355 huff ? "encoded" : "raw", len);
1365 1356
1366 if ((size_t) len > h2c->state.field_limit) { 1357 h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
1358 ngx_http_v2_module);
1359
1360 if ((size_t) len > h2scf->max_field_size) {
1367 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0, 1361 ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
1368 "client exceeded http2_max_field_size limit"); 1362 "client exceeded http2_max_field_size limit");
1369 1363
1370 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM); 1364 return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
1371 } 1365 }
1372 1366
1373 h2c->state.field_limit -= len;
1374 h2c->state.field_rest = len; 1367 h2c->state.field_rest = len;
1375 1368
1376 if (h2c->state.stream == NULL && !h2c->state.index) { 1369 if (h2c->state.stream == NULL && !h2c->state.index) {
1377 return ngx_http_v2_state_field_skip(h2c, pos, end); 1370 return ngx_http_v2_state_field_skip(h2c, pos, end);
1378 } 1371 }