Define NGHTTP2_CLIENT_CONNECTION_PREFACE macro
NGHTTP2_CLIENT_CONNECTION_PREFACE has the same content with NGHTTP2_CLIENT_CONNECTION_HEADER, which is now obsoleted by NGHTTP2_CLIENT_CONNECTION_PREFACE.
This commit is contained in:
parent
ab2dc5967d
commit
60a2c260a5
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<ClientHandler*>(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<ClientHandler*>(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),
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue