diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 969726f4..c1a725cb 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -55,13 +55,13 @@ extern "C" { * The protocol version identification string of this library * supports. This identifier is used if HTTP/2 is used over TLS. */ -#define NGHTTP2_PROTO_VERSION_ID "h2-14" +#define NGHTTP2_PROTO_VERSION_ID "h2" /** * @macro * * The length of :macro:`NGHTTP2_PROTO_VERSION_ID`. */ -#define NGHTTP2_PROTO_VERSION_ID_LEN 5 +#define NGHTTP2_PROTO_VERSION_ID_LEN 2 /** * @macro @@ -72,7 +72,7 @@ extern "C" { * extension `_. This is useful * to process incoming ALPN tokens in wire format. */ -#define NGHTTP2_PROTO_ALPN "\x5h2-14" +#define NGHTTP2_PROTO_ALPN "\x2h2" /** * @macro @@ -88,14 +88,14 @@ extern "C" { * supports. This identifier is used if HTTP/2 is used over cleartext * TCP. */ -#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c-14" +#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c" /** * @macro * * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`. */ -#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 6 +#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 3 struct nghttp2_session; /** diff --git a/src/shrpx.cc b/src/shrpx.cc index 8904ce13..7e1ff06e 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -769,7 +769,7 @@ bool conf_exists(const char *path) { } // namespace namespace { -const char *DEFAULT_NPN_LIST = "h2,h2-16," NGHTTP2_PROTO_VERSION_ID "," +const char *DEFAULT_NPN_LIST = "h2,h2-16,h2-14," #ifdef HAVE_SPDYLAY "spdy/3.1," #endif // HAVE_SPDYLAY diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 58d9eb74..4554f428 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -454,9 +454,7 @@ int ClientHandler::validate_next_proto() { next_proto_len)) { break; } - if (util::check_h2_is_selected(next_proto, next_proto_len) || - (next_proto_len == sizeof("h2-16") - 1 && - memcmp("h2-16", next_proto, next_proto_len) == 0)) { + if (util::check_h2_is_selected(next_proto, next_proto_len)) { on_read_ = &ClientHandler::upstream_http2_connhd_read; diff --git a/src/util.cc b/src/util.cc index d08d8b5b..9c59f92e 100644 --- a/src/util.cc +++ b/src/util.cc @@ -763,9 +763,9 @@ int64_t to_time64(const timeval &tv) { } bool check_h2_is_selected(const unsigned char *proto, size_t len) { - return streq_l(NGHTTP2_H2, proto, len) || + return streq_l(NGHTTP2_PROTO_VERSION_ID, proto, len) || streq_l(NGHTTP2_H2_16, proto, len) || - streq_l(NGHTTP2_PROTO_VERSION_ID, proto, len); + streq_l(NGHTTP2_H2_14, proto, len); } namespace { @@ -785,23 +785,23 @@ bool select_h2(const unsigned char **out, unsigned char *outlen, bool select_h2(const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen) { - return select_h2(out, outlen, in, inlen, NGHTTP2_H2_ALPN, - str_size(NGHTTP2_H2_ALPN)) || + return select_h2(out, outlen, in, inlen, NGHTTP2_PROTO_ALPN, + str_size(NGHTTP2_PROTO_ALPN)) || select_h2(out, outlen, in, inlen, NGHTTP2_H2_16_ALPN, str_size(NGHTTP2_H2_16_ALPN)) || - select_h2(out, outlen, in, inlen, NGHTTP2_PROTO_ALPN, - str_size(NGHTTP2_PROTO_ALPN)); + select_h2(out, outlen, in, inlen, NGHTTP2_H2_14_ALPN, + str_size(NGHTTP2_H2_14_ALPN)); } std::vector get_default_alpn() { auto res = std::vector(str_size(NGHTTP2_PROTO_ALPN) + str_size(NGHTTP2_H2_16_ALPN) + - str_size(NGHTTP2_H2_ALPN)); + str_size(NGHTTP2_H2_14_ALPN)); auto p = std::begin(res); - p = std::copy_n(NGHTTP2_H2_ALPN, str_size(NGHTTP2_H2_ALPN), p); - p = std::copy_n(NGHTTP2_H2_16_ALPN, str_size(NGHTTP2_H2_16_ALPN), p); p = std::copy_n(NGHTTP2_PROTO_ALPN, str_size(NGHTTP2_PROTO_ALPN), p); + p = std::copy_n(NGHTTP2_H2_16_ALPN, str_size(NGHTTP2_H2_16_ALPN), p); + p = std::copy_n(NGHTTP2_H2_14_ALPN, str_size(NGHTTP2_H2_14_ALPN), p); return res; } diff --git a/src/util.h b/src/util.h index f20624d5..06861f6c 100644 --- a/src/util.h +++ b/src/util.h @@ -46,13 +46,13 @@ namespace nghttp2 { // The additional HTTP/2 protocol ALPN protocol identifier we also -// supports for our applications. This will be removed once HTTP/2 -// specification is finalized. +// supports for our applications to make smooth migration into final +// h2 ALPN ID. #define NGHTTP2_H2_16_ALPN "\x5h2-16" #define NGHTTP2_H2_16 "h2-16" -#define NGHTTP2_H2_ALPN "\x2h2" -#define NGHTTP2_H2 "h2" +#define NGHTTP2_H2_14_ALPN "\x5h2-14" +#define NGHTTP2_H2_14 "h2-14" namespace util { diff --git a/src/util_test.cc b/src/util_test.cc index 21d992d8..c1100b76 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -184,7 +184,7 @@ void test_util_select_h2(void) { unsigned char outlen = 0; // Check single entry and select it. - const unsigned char t1[] = "\x5h2-14"; + const unsigned char t1[] = "\x2h2"; CU_ASSERT(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1)); CU_ASSERT( memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); @@ -198,9 +198,10 @@ void test_util_select_h2(void) { const unsigned char t2[] = "\x6h2-14"; CU_ASSERT(!util::select_h2(&out, &outlen, t2, sizeof(t2) - 1)); - // Check the case where h2-14 is located after bogus ID. - const unsigned char t3[] = "\x2h3\x5h2-14"; + // Check the case where h2 is located after bogus ID. + const unsigned char t3[] = "\x2h3\x2h2"; CU_ASSERT(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1)); + CU_ASSERT( memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); diff --git a/tests/nghttp2_npn_test.c b/tests/nghttp2_npn_test.c index bae6082b..cbd65b71 100644 --- a/tests/nghttp2_npn_test.c +++ b/tests/nghttp2_npn_test.c @@ -30,9 +30,8 @@ #include static void http2(void) { - const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.', - '1', 5, 'h', '2', '-', '1', '4', 6, - 's', 'p', 'd', 'y', '/', '3'}; + const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.', '1', 2, + 'h', '2', 6, 's', 'p', 'd', 'y', '/', '3'}; unsigned char outlen; unsigned char *out; CU_ASSERT(1 == nghttp2_select_next_protocol(&out, &outlen, p, sizeof(p)));