From 459a269049d2a735f42f54e24c9d6f1cada5e0b2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 26 Jul 2013 01:38:04 +0900 Subject: [PATCH] Define HTTP/2.0 protocol version ID --- lib/includes/nghttp2/nghttp2.h | 3 +++ lib/nghttp2_npn.c | 3 ++- src/HttpServer.cc | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 0fff133f..46b63ec5 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -35,6 +35,9 @@ extern "C" { #include +#define NGHTTP2_PROTO_VERSION_ID "HTTP-draft-04/2.0" +#define NGHTTP2_PROTO_VERSION_ID_LEN 17 + struct nghttp2_session; /** * @struct diff --git a/lib/nghttp2_npn.c b/lib/nghttp2_npn.c index 348a8192..ead53d61 100644 --- a/lib/nghttp2_npn.c +++ b/lib/nghttp2_npn.c @@ -32,7 +32,8 @@ int nghttp2_select_next_protocol(unsigned char **out, unsigned char *outlen, int http_selected = 0; unsigned int i = 0; for(; i < inlen; i += in[i]+1) { - if(in[i] == 17 && memcmp(&in[i+1], "HTTP-draft-04/2.0", in[i]) == 0) { + if(in[i] == NGHTTP2_PROTO_VERSION_ID_LEN && + memcmp(&in[i+1], NGHTTP2_PROTO_VERSION_ID, in[i]) == 0) { *out = (unsigned char*)&in[i+1]; *outlen = in[i]; return 1; diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 996e3d81..84c82474 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -365,7 +365,7 @@ int Http2Handler::verify_npn_result() if(sessions_->get_config()->verbose) { std::cout << "The negotiated next protocol: " << proto << std::endl; } - if(proto == "HTTP-draft-04/2.0") { + if(proto == NGHTTP2_PROTO_VERSION_ID) { return 0; } } @@ -1003,7 +1003,8 @@ int HttpServer::run() } proto_list[0] = 17; - memcpy(&proto_list[1], "HTTP-draft-04/2.0", 17); + memcpy(&proto_list[1], NGHTTP2_PROTO_VERSION_ID, + NGHTTP2_PROTO_VERSION_ID_LEN); next_proto.first = proto_list; next_proto.second = 18;