src: Announce h2 ALPN
This commit is contained in:
parent
2fc1dd77d2
commit
ab93a700ce
|
@ -636,7 +636,7 @@ bool conf_exists(const char *path) {
|
|||
} // namespace
|
||||
|
||||
namespace {
|
||||
const char *DEFAULT_NPN_LIST = "h2-16," NGHTTP2_PROTO_VERSION_ID ","
|
||||
const char *DEFAULT_NPN_LIST = "h2,h2-16," NGHTTP2_PROTO_VERSION_ID ","
|
||||
#ifdef HAVE_SPDYLAY
|
||||
"spdy/3.1,"
|
||||
#endif // HAVE_SPDYLAY
|
||||
|
|
|
@ -55,6 +55,10 @@ template <typename T, size_t N> constexpr size_t array_size(T (&)[N]) {
|
|||
return N;
|
||||
}
|
||||
|
||||
template <typename T, size_t N> constexpr size_t str_size(T (&)[N]) {
|
||||
return N - 1;
|
||||
}
|
||||
|
||||
// inspired by <http://blog.korfuri.fr/post/go-defer-in-cpp/>, but our
|
||||
// template can take functions returning other than void.
|
||||
template <typename F, typename... T> struct Defer {
|
||||
|
|
25
src/util.cc
25
src/util.cc
|
@ -44,6 +44,7 @@
|
|||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include "timegm.h"
|
||||
#include "template.h"
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
|
@ -756,9 +757,9 @@ int64_t to_time64(const timeval &tv) {
|
|||
}
|
||||
|
||||
bool check_h2_is_selected(const unsigned char *proto, size_t len) {
|
||||
return streq(NGHTTP2_PROTO_VERSION_ID, NGHTTP2_PROTO_VERSION_ID_LEN, proto,
|
||||
len) ||
|
||||
streq(NGHTTP2_H2_16_ID, NGHTTP2_H2_16_ID_LEN, proto, len);
|
||||
return streq_l(NGHTTP2_H2, proto, len) ||
|
||||
streq_l(NGHTTP2_H2_16, proto, len) ||
|
||||
streq_l(NGHTTP2_PROTO_VERSION_ID, proto, len);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -778,19 +779,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_16_ALPN,
|
||||
NGHTTP2_H2_16_ALPN_LEN) ||
|
||||
return select_h2(out, outlen, in, inlen, NGHTTP2_H2_ALPN,
|
||||
str_size(NGHTTP2_H2_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,
|
||||
NGHTTP2_PROTO_ALPN_LEN);
|
||||
str_size(NGHTTP2_PROTO_ALPN));
|
||||
}
|
||||
|
||||
std::vector<unsigned char> get_default_alpn() {
|
||||
auto res = std::vector<unsigned char>(NGHTTP2_PROTO_ALPN_LEN +
|
||||
NGHTTP2_H2_16_ALPN_LEN);
|
||||
auto res = std::vector<unsigned char>(str_size(NGHTTP2_PROTO_ALPN) +
|
||||
str_size(NGHTTP2_H2_16_ALPN) +
|
||||
str_size(NGHTTP2_H2_ALPN));
|
||||
auto p = std::begin(res);
|
||||
|
||||
p = std::copy_n(NGHTTP2_H2_16_ALPN, NGHTTP2_H2_16_ALPN_LEN, p);
|
||||
p = std::copy_n(NGHTTP2_PROTO_ALPN, NGHTTP2_PROTO_ALPN_LEN, p);
|
||||
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);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
12
src/util.h
12
src/util.h
|
@ -48,9 +48,10 @@ namespace nghttp2 {
|
|||
// supports for our applications. This will be removed once HTTP/2
|
||||
// specification is finalized.
|
||||
#define NGHTTP2_H2_16_ALPN "\x5h2-16"
|
||||
#define NGHTTP2_H2_16_ALPN_LEN (sizeof(NGHTTP2_H2_16_ALPN) - 1)
|
||||
#define NGHTTP2_H2_16_ID "h2-16"
|
||||
#define NGHTTP2_H2_16_ID_LEN (sizeof(NGHTTP2_H2_16_ID) - 1)
|
||||
#define NGHTTP2_H2_16 "h2-16"
|
||||
|
||||
#define NGHTTP2_H2_ALPN "\x2h2"
|
||||
#define NGHTTP2_H2 "h2"
|
||||
|
||||
namespace util {
|
||||
|
||||
|
@ -322,6 +323,11 @@ bool streq(InputIt1 a, size_t alen, InputIt2 b, size_t blen) {
|
|||
return std::equal(a, a + alen, b);
|
||||
}
|
||||
|
||||
template <typename InputIt, size_t N>
|
||||
bool streq_l(const char (&a)[N], InputIt b, size_t blen) {
|
||||
return streq(a, N - 1, b, blen);
|
||||
}
|
||||
|
||||
bool strifind(const char *a, const char *b);
|
||||
|
||||
// Lowercase |s| in place.
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "template.h"
|
||||
|
||||
using namespace nghttp2;
|
||||
|
||||
|
@ -197,8 +198,8 @@ void test_util_select_h2(void) {
|
|||
// picked up because it has precedence over the other.
|
||||
const unsigned char t6[] = "\x5h2-14\x5h2-16";
|
||||
CU_ASSERT(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1));
|
||||
CU_ASSERT(memcmp(NGHTTP2_H2_16_ID, out, NGHTTP2_H2_16_ID_LEN) == 0);
|
||||
CU_ASSERT(NGHTTP2_H2_16_ID_LEN == outlen);
|
||||
CU_ASSERT(memcmp(NGHTTP2_H2_16, out, str_size(NGHTTP2_H2_16)) == 0);
|
||||
CU_ASSERT(str_size(NGHTTP2_H2_16) == outlen);
|
||||
}
|
||||
|
||||
void test_util_ipv6_numeric_addr(void) {
|
||||
|
|
Loading…
Reference in New Issue