From 34581d830d1341d3e061e4fc73edec3ca94923e0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 30 Mar 2014 21:30:47 +0900 Subject: [PATCH] Define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID This identifier string is used if HTTP/2 is used over cleartext TCP. --- lib/includes/nghttp2/nghttp2.h | 19 ++++++++++++++++++- src/nghttp.cc | 2 +- src/shrpx_client_handler.cc | 2 +- src/shrpx_downstream.cc | 8 +++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 331ee4e4..e25e8162 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -38,7 +38,8 @@ extern "C" { /** * @macro * - * The protocol version identification of this library supports. + * 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-10" /** @@ -48,6 +49,22 @@ extern "C" { */ #define NGHTTP2_PROTO_VERSION_ID_LEN 5 +/** + * @macro + * + * The protocol version identification string of this library + * supports. This identifier is used if HTTP/2 is used over cleartext + * TCP. + */ +#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "h2c-10" + +/** + * @macro + * + * The length of :macro:`NGHTTP2_CLEARTEXT_PROTO_VERSION_ID`. + */ +#define NGHTTP2_CLEARTEXT_PROTO_VERSION_ID_LEN 6 + struct nghttp2_session; /** * @struct diff --git a/src/nghttp.cc b/src/nghttp.cc index 18ea572d..d27c0b4d 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -611,7 +611,7 @@ struct HttpClient { req += hostport; req += "\r\n" "Connection: Upgrade, HTTP2-Settings\r\n" - "Upgrade: " NGHTTP2_PROTO_VERSION_ID "\r\n" + "Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n" "HTTP2-Settings: "; req += token68; req += "\r\n" diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 3b6f2e40..145cc1f8 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -542,7 +542,7 @@ int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) set_bev_cb(upstream_http2_connhd_readcb, upstream_writecb, upstream_eventcb); static char res[] = "HTTP/1.1 101 Switching Protocols\r\n" "Connection: Upgrade\r\n" - "Upgrade: " NGHTTP2_PROTO_VERSION_ID "\r\n" + "Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n" "\r\n"; rv = bufferevent_write(bev_, res, sizeof(res) - 1); if(rv != 0) { diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index c7e6c95f..1cefe7bb 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -734,10 +734,12 @@ bool Downstream::http2_upgrade_request() const bool upgrade_seen = false; bool http2_settings_seen = false; for(auto& hd : request_headers_) { - // For now just check NGHTTP2_PROTO_VERSION_ID in Upgrade header - // field and existence of HTTP2-Settings header field. + // For now just check NGHTTP2_CLEARTEXT_PROTO_VERSION_ID in + // Upgrade header field and existence of HTTP2-Settings header + // field. if(util::strieq(hd.first.c_str(), "upgrade")) { - if(util::strieq(hd.second.c_str(), NGHTTP2_PROTO_VERSION_ID)) { + if(util::strieq(hd.second.c_str(), + NGHTTP2_CLEARTEXT_PROTO_VERSION_ID)) { upgrade_seen = true; } } else if(util::strieq(hd.first.c_str(), "http2-settings")) {