h2load: Support ALPN

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-22 01:13:18 +09:00
parent fa4f03525e
commit bded1d1115
1 changed files with 40 additions and 21 deletions

View File

@ -462,13 +462,8 @@ void eventcb(bufferevent *bev, short events, void *ptr)
unsigned int next_proto_len; unsigned int next_proto_len;
SSL_get0_next_proto_negotiated(client->ssl, SSL_get0_next_proto_negotiated(client->ssl,
&next_proto, &next_proto_len); &next_proto, &next_proto_len);
for(int i = 0; i < 2; ++i) {
if(!next_proto) { if(next_proto) {
debug_nextproto_error();
client->fail();
return;
}
if(util::check_h2_is_selected(next_proto, next_proto_len)) { if(util::check_h2_is_selected(next_proto, next_proto_len)) {
client->session = util::make_unique<Http2Session>(client); client->session = util::make_unique<Http2Session>(client);
} else { } else {
@ -489,6 +484,20 @@ void eventcb(bufferevent *bev, short events, void *ptr)
return; return;
#endif // !HAVE_SPDYLAY #endif // !HAVE_SPDYLAY
} }
}
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
SSL_get0_alpn_selected(client->ssl, &next_proto, &next_proto_len);
#else // OPENSSL_VERSION_NUMBER < 0x10002000L
break;
#endif // OPENSSL_VERSION_NUMBER < 0x10002000L
}
if(!next_proto) {
debug_nextproto_error();
client->fail();
return;
}
} else { } else {
switch(config.no_tls_proto) { switch(config.no_tls_proto) {
case Config::PROTO_HTTP2: case Config::PROTO_HTTP2:
@ -974,6 +983,16 @@ int main(int argc, char **argv)
SSL_CTX_set_next_proto_select_cb(ssl_ctx, SSL_CTX_set_next_proto_select_cb(ssl_ctx,
client_select_next_proto_cb, nullptr); client_select_next_proto_cb, nullptr);
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
auto proto_list = util::get_default_alpn();
#ifdef HAVE_SPDYLAY
static const char spdy_proto_list[] = "\x8spdy/3.1\x6spdy/3\x6spdy/2";
std::copy(spdy_proto_list, spdy_proto_list + sizeof(spdy_proto_list) - 1,
std::back_inserter(proto_list));
#endif // HAVE_SPDYLAY
SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size());
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
std::vector<std::string> reqlines; std::vector<std::string> reqlines;
if(config.ifile.empty()) { if(config.ifile.empty()) {