h2load: Show application protocol with OpenSSL < 1.0.2
This commit also fixes the problem that application protocol is not shown if cleartext spdy is used.
This commit is contained in:
parent
55bf22081e
commit
b051ddec2a
|
@ -586,51 +586,37 @@ int Client::connection_made() {
|
|||
|
||||
const unsigned char *next_proto = nullptr;
|
||||
unsigned int next_proto_len;
|
||||
|
||||
SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||
if (next_proto == nullptr) {
|
||||
SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len);
|
||||
}
|
||||
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||
|
||||
next_proto = nullptr;
|
||||
if (next_proto) {
|
||||
if (util::check_h2_is_selected(next_proto, next_proto_len)) {
|
||||
session = make_unique<Http2Session>(this);
|
||||
break;
|
||||
} else if (util::streq_l(NGHTTP2_H1_1, next_proto, next_proto_len)) {
|
||||
session = make_unique<Http1Session>(this);
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_SPDYLAY
|
||||
else {
|
||||
auto spdy_version =
|
||||
spdylay_npn_get_version(next_proto, next_proto_len);
|
||||
auto spdy_version = spdylay_npn_get_version(next_proto, next_proto_len);
|
||||
if (spdy_version) {
|
||||
session = make_unique<SpdySession>(this, spdy_version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // HAVE_SPDYLAY
|
||||
|
||||
next_proto = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||
SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len);
|
||||
auto proto = std::string(reinterpret_cast<const char *>(next_proto),
|
||||
next_proto_len);
|
||||
|
||||
if (proto.empty()) {
|
||||
std::cout
|
||||
<< "No protocol negotiated. Fallback behaviour may be activated"
|
||||
<< std::endl;
|
||||
break;
|
||||
// Just assign next_proto to selected_proto anyway to show the
|
||||
// negotiation result.
|
||||
selected_proto.assign(next_proto, next_proto + next_proto_len);
|
||||
} else {
|
||||
selected_proto = proto;
|
||||
report_app_info();
|
||||
}
|
||||
#else // OPENSSL_VERSION_NUMBER < 0x10002000L
|
||||
break;
|
||||
#endif // OPENSSL_VERSION_NUMBER < 0x10002000L
|
||||
}
|
||||
std::cout << "No protocol negotiated. Fallback behaviour may be activated"
|
||||
<< std::endl;
|
||||
|
||||
if (!next_proto) {
|
||||
for (const auto &proto : config.npn_list) {
|
||||
if (std::equal(NGHTTP2_H1_1_ALPN,
|
||||
NGHTTP2_H1_1_ALPN + str_size(NGHTTP2_H1_1_ALPN),
|
||||
|
@ -639,9 +625,15 @@ int Client::connection_made() {
|
|||
<< "Server does not support NPN/ALPN. Falling back to HTTP/1.1."
|
||||
<< std::endl;
|
||||
session = make_unique<Http1Session>(this);
|
||||
selected_proto = NGHTTP2_H1_1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!selected_proto.empty()) {
|
||||
report_app_info();
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
std::cout
|
||||
|
@ -653,34 +645,36 @@ int Client::connection_made() {
|
|||
disconnect();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (config.no_tls_proto) {
|
||||
case Config::PROTO_HTTP2:
|
||||
session = make_unique<Http2Session>(this);
|
||||
selected_proto = NGHTTP2_CLEARTEXT_PROTO_VERSION_ID;
|
||||
report_app_info();
|
||||
break;
|
||||
case Config::PROTO_HTTP1_1:
|
||||
session = make_unique<Http1Session>(this);
|
||||
selected_proto = NGHTTP2_H1_1;
|
||||
report_app_info();
|
||||
break;
|
||||
#ifdef HAVE_SPDYLAY
|
||||
case Config::PROTO_SPDY2:
|
||||
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY2);
|
||||
selected_proto = "spdy/2";
|
||||
break;
|
||||
case Config::PROTO_SPDY3:
|
||||
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3);
|
||||
selected_proto = "spdy/3";
|
||||
break;
|
||||
case Config::PROTO_SPDY3_1:
|
||||
session = make_unique<SpdySession>(this, SPDYLAY_PROTO_SPDY3_1);
|
||||
selected_proto = "spdy/3.1";
|
||||
break;
|
||||
#endif // HAVE_SPDYLAY
|
||||
default:
|
||||
// unreachable
|
||||
assert(0);
|
||||
}
|
||||
|
||||
report_app_info();
|
||||
}
|
||||
|
||||
state = CLIENT_CONNECTED;
|
||||
|
|
Loading…
Reference in New Issue