diff --git a/examples/client.c b/examples/client.c index 5acac92a..305d79ef 100644 --- a/examples/client.c +++ b/examples/client.c @@ -613,8 +613,8 @@ static void fetch_uri(const struct URI *uri) connection.want_io = IO_NONE; /* Send connection header in blocking I/O mode */ - SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_HEADER, - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); /* Here make file descriptor non-block */ make_non_block(fd); diff --git a/examples/libevent-client.c b/examples/libevent-client.c index 7734e607..2c635b8b 100644 --- a/examples/libevent-client.c +++ b/examples/libevent-client.c @@ -371,8 +371,8 @@ static void send_client_connection_header(http2_session_data *session_data) int rv; bufferevent_write(session_data->bev, - NGHTTP2_CLIENT_CONNECTION_HEADER, - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); rv = nghttp2_submit_settings(session_data->session, NGHTTP2_FLAG_NONE, iv, ARRLEN(iv)); if(rv != 0) { diff --git a/examples/libevent-server.c b/examples/libevent-server.c index 2fcff6c0..fdf71852 100644 --- a/examples/libevent-server.c +++ b/examples/libevent-server.c @@ -190,7 +190,7 @@ static http2_session_data* create_http2_session_data(app_context *app_ctx, (app_ctx->evbase, fd, ssl, BUFFEREVENT_SSL_ACCEPTING, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS); - session_data->handshake_leftlen = NGHTTP2_CLIENT_CONNECTION_HEADER_LEN; + session_data->handshake_leftlen = NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN; rv = getnameinfo(addr, addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST); if(rv != 0) { session_data->client_addr = strdup("(unknown)"); @@ -629,9 +629,9 @@ static void handshake_readcb(struct bufferevent *bev, void *ptr) uint8_t data[24]; struct evbuffer *input = bufferevent_get_input(session_data->bev); int readlen = evbuffer_remove(input, data, session_data->handshake_leftlen); - const char *conhead = NGHTTP2_CLIENT_CONNECTION_HEADER; + const char *conhead = NGHTTP2_CLIENT_CONNECTION_PREFACE; - if(memcmp(conhead + NGHTTP2_CLIENT_CONNECTION_HEADER_LEN + if(memcmp(conhead + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN - session_data->handshake_leftlen, data, readlen) != 0) { delete_http2_session_data(session_data); return; diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 1348024b..331ee4e4 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -135,18 +135,36 @@ typedef struct { */ #define NGHTTP2_MAX_HEADER_TABLE_SIZE (1 << 16) + /** * @macro * - * The client connection header. + * The client connection preface. */ -#define NGHTTP2_CLIENT_CONNECTION_HEADER "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" +#define NGHTTP2_CLIENT_CONNECTION_PREFACE "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + +/** + * @macro + * + * The length of :macro:`NGHTTP2_CLIENT_CONNECTION_PREFACE`. + */ +#define NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN 24 + +/** + * @macro + * + * The client connection header. This macro is obsoleted by + * NGHTTP2_CLIENT_CONNECTION_PREFACE. + */ +#define NGHTTP2_CLIENT_CONNECTION_HEADER NGHTTP2_CLIENT_CONNECTION_PREFACE + /** * @macro * * The length of :macro:`NGHTTP2_CLIENT_CONNECTION_HEADER`. */ -#define NGHTTP2_CLIENT_CONNECTION_HEADER_LEN 24 +#define NGHTTP2_CLIENT_CONNECTION_HEADER_LEN \ + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN /** * @enum diff --git a/python/cnghttp2.pxd b/python/cnghttp2.pxd index b3ccb35d..9fefc832 100644 --- a/python/cnghttp2.pxd +++ b/python/cnghttp2.pxd @@ -25,7 +25,7 @@ from libc.stdint cimport uint8_t, uint16_t, uint32_t, int32_t cdef extern from 'nghttp2/nghttp2.h': const char NGHTTP2_PROTO_VERSION_ID[] - const char NGHTTP2_CLIENT_CONNECTION_HEADER[] + const char NGHTTP2_CLIENT_CONNECTION_PREFACE[] const size_t NGHTTP2_INITIAL_WINDOW_SIZE ctypedef struct nghttp2_session: diff --git a/python/nghttp2.pyx b/python/nghttp2.pyx index 596ac0a2..9741619c 100644 --- a/python/nghttp2.pyx +++ b/python/nghttp2.pyx @@ -901,7 +901,7 @@ if asyncio: def connection_made(self, transport): self.transport = transport - self.connection_header = cnghttp2.NGHTTP2_CLIENT_CONNECTION_HEADER + self.connection_header = cnghttp2.NGHTTP2_CLIENT_CONNECTION_PREFACE sock = self.transport.get_extra_info('socket') sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) ssl_ctx = self.transport.get_extra_info('sslcontext') diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 161012ac..6cee9448 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -313,7 +313,7 @@ Http2Handler::Http2Handler(Sessions *sessions, settings_timerev_(nullptr), pending_data_(nullptr), pending_datalen_(0), - left_connhd_len_(NGHTTP2_CLIENT_CONNECTION_HEADER_LEN), + left_connhd_len_(NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN), fd_(fd) { nghttp2_buf_wrap_init(&sendbuf_, sendbufarray_, sizeof(sendbufarray_)); @@ -625,9 +625,9 @@ int Http2Handler::on_read() if(left_connhd_len_ > 0) { auto len = std::min(left_connhd_len_, nread); - const char *conhead = NGHTTP2_CLIENT_CONNECTION_HEADER; + const char *conhead = NGHTTP2_CLIENT_CONNECTION_PREFACE; - if(memcmp(conhead + NGHTTP2_CLIENT_CONNECTION_HEADER_LEN - + if(memcmp(conhead + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN - left_connhd_len_, bufp, len) != 0) { return -1; } diff --git a/src/h2load_http2_session.cc b/src/h2load_http2_session.cc index 6df6435d..c5e2107f 100644 --- a/src/h2load_http2_session.cc +++ b/src/h2load_http2_session.cc @@ -135,8 +135,8 @@ void Http2Session::on_connect() extra_connection_window); } - bufferevent_write(client_->bev, NGHTTP2_CLIENT_CONNECTION_HEADER, - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + bufferevent_write(client_->bev, NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); } void Http2Session::submit_request() diff --git a/src/nghttp.cc b/src/nghttp.cc index 7a9871cd..18ea572d 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -713,8 +713,8 @@ struct HttpClient { } } // Send connection header here - bufferevent_write(bev, NGHTTP2_CLIENT_CONNECTION_HEADER, - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + bufferevent_write(bev, NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); // If upgrade succeeds, the SETTINGS value sent with // HTTP2-Settings header field has already been submitted to // session object. diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index e14c2238..3b6f2e40 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -138,7 +138,7 @@ namespace { void upstream_http2_connhd_readcb(bufferevent *bev, void *arg) { // This callback assumes upstream is Http2Upstream. - uint8_t data[NGHTTP2_CLIENT_CONNECTION_HEADER_LEN]; + uint8_t data[NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN]; auto handler = static_cast(arg); auto leftlen = handler->get_left_connhd_len(); auto input = bufferevent_get_input(bev); @@ -147,8 +147,8 @@ void upstream_http2_connhd_readcb(bufferevent *bev, void *arg) delete handler; return; } - if(memcmp(NGHTTP2_CLIENT_CONNECTION_HEADER + - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN - leftlen, + if(memcmp(NGHTTP2_CLIENT_CONNECTION_PREFACE + + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN - leftlen, data, readlen) != 0) { // There is no downgrade path here. Just drop the connection. if(LOG_ENABLED(INFO)) { @@ -175,7 +175,7 @@ namespace { void upstream_http1_connhd_readcb(bufferevent *bev, void *arg) { // This callback assumes upstream is HttpsUpstream. - uint8_t data[NGHTTP2_CLIENT_CONNECTION_HEADER_LEN]; + uint8_t data[NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN]; auto handler = static_cast(arg); auto leftlen = handler->get_left_connhd_len(); auto input = bufferevent_get_input(bev); @@ -184,15 +184,15 @@ void upstream_http1_connhd_readcb(bufferevent *bev, void *arg) delete handler; return; } - if(memcmp(NGHTTP2_CLIENT_CONNECTION_HEADER + - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN - leftlen, + if(memcmp(NGHTTP2_CLIENT_CONNECTION_PREFACE + + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN - leftlen, data, readlen) != 0) { if(LOG_ENABLED(INFO)) { CLOG(INFO, handler) << "This is HTTP/1.1 connection, " << "but may be upgraded to HTTP/2 later."; } // Reset header length for later HTTP/2 upgrade - handler->set_left_connhd_len(NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + handler->set_left_connhd_len(NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); handler->set_bev_cb(upstream_readcb, upstream_writecb, upstream_eventcb); if(handler->on_read() != 0) { delete handler; @@ -254,7 +254,7 @@ ClientHandler::ClientHandler(bufferevent *bev, bev_(bev), http2session_(nullptr), ssl_(ssl), - left_connhd_len_(NGHTTP2_CLIENT_CONNECTION_HEADER_LEN), + left_connhd_len_(NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN), fd_(fd), should_close_after_write_(false), tls_handshake_(false), diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index bda23d38..30791478 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1219,8 +1219,8 @@ int Http2Session::on_connect() } } - rv = bufferevent_write(bev_, NGHTTP2_CLIENT_CONNECTION_HEADER, - NGHTTP2_CLIENT_CONNECTION_HEADER_LEN); + rv = bufferevent_write(bev_, NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); if(rv != 0) { SSLOG(FATAL, this) << "bufferevent_write() failed"; return -1;