Use switch to avoid many if-else-if

This commit is contained in:
Tatsuhiro Tsujikawa 2021-09-04 17:35:33 +09:00
parent 2f941c7fb3
commit 31b5b78dc1
1 changed files with 11 additions and 6 deletions

View File

@ -360,16 +360,21 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
return NGHTTP2_ERR_IGN_HTTP_HEADER;
}
if (nv->token == NGHTTP2_TOKEN__METHOD) {
switch (nv->token) {
case NGHTTP2_TOKEN__METHOD:
rv = nghttp2_check_method(nv->value->base, nv->value->len);
} else if (nv->token == NGHTTP2_TOKEN__PATH) {
break;
case NGHTTP2_TOKEN__PATH:
rv = nghttp2_check_path(nv->value->base, nv->value->len);
} else if (nv->token == NGHTTP2_TOKEN__AUTHORITY ||
nv->token == NGHTTP2_TOKEN_HOST) {
break;
case NGHTTP2_TOKEN__AUTHORITY:
case NGHTTP2_TOKEN_HOST:
rv = nghttp2_check_authority(nv->value->base, nv->value->len);
} else if (nv->token == NGHTTP2_TOKEN__SCHEME) {
break;
case NGHTTP2_TOKEN__SCHEME:
rv = check_scheme(nv->value->base, nv->value->len);
} else {
break;
default:
rv = nghttp2_check_header_value(nv->value->base, nv->value->len);
}