Announce h2, final HTTP/2 ALPN identifier

This commit is contained in:
Tatsuhiro Tsujikawa 2015-04-05 23:00:59 +09:00
parent 87602e5d72
commit 3e50ef439d
7 changed files with 26 additions and 28 deletions

View File

@ -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 <https://tools.ietf.org/html/rfc7301>`_. 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;
/**

View File

@ -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

View File

@ -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;

View File

@ -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<unsigned char> get_default_alpn() {
auto res = std::vector<unsigned char>(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;
}

View File

@ -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 {

View File

@ -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);

View File

@ -30,9 +30,8 @@
#include <nghttp2/nghttp2.h>
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)));