diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc index 009842f31c2..d4a16d80ada 100644 --- a/proxy/http2/Http2ClientSession.cc +++ b/proxy/http2/Http2ClientSession.cc @@ -177,8 +177,8 @@ Http2ClientSession::start() VIO *read_vio = this->do_io_read(this, INT64_MAX, this->read_buffer); write_vio = this->do_io_write(this, INT64_MAX, this->_write_buffer_reader); - this->connection_state.init(); - send_connection_event(&this->connection_state, HTTP2_SESSION_EVENT_INIT, this); + this->connection_state.init(this); + this->connection_state.send_connection_preface(); if (this->_read_buffer_reader->is_read_avail_more_than(0)) { this->handleEvent(VC_EVENT_READ_READY, read_vio); diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 323790ec1a3..6f4f2b3aeae 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -1040,8 +1040,9 @@ Http2ConnectionState::Http2ConnectionState() : stream_list() } void -Http2ConnectionState::init() +Http2ConnectionState::init(Http2ClientSession *ssn) { + ua_session = ssn; this->_server_rwnd = Http2::initial_window_size; local_hpack_handle = new HpackHandle(HTTP2_HEADER_TABLE_SIZE); @@ -1054,6 +1055,32 @@ Http2ConnectionState::init() _cop.start(); } +/** + Send connection preface + + The client connection preface is HTTP2_CONNECTION_PREFACE. + The server connection preface consists of a potentially emptry SETTINGS frame. + + Details in [RFC 7540] 3.5. HTTP/2 Connection Preface + + TODO: send client connection preface if the connection is outbound + */ +void +Http2ConnectionState::send_connection_preface() +{ + REMEMBER(NO_EVENT, this->recursion) + + Http2ConnectionSettings configured_settings; + configured_settings.settings_from_configs(); + configured_settings.set(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, _adjust_concurrent_stream()); + + send_settings_frame(configured_settings); + + if (server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) > HTTP2_INITIAL_WINDOW_SIZE) { + send_window_update_frame(0, server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - HTTP2_INITIAL_WINDOW_SIZE); + } +} + void Http2ConnectionState::destroy() { @@ -1100,33 +1127,6 @@ Http2ConnectionState::main_event_handler(int event, void *edata) } ++recursion; switch (event) { - // Initialize HTTP/2 Connection - case HTTP2_SESSION_EVENT_INIT: { - ink_assert(this->ua_session == nullptr); - this->ua_session = static_cast(edata); - REMEMBER(event, this->recursion); - - // [RFC 7540] 3.5. HTTP/2 Connection Preface. Upon establishment of a TCP connection and - // determination that HTTP/2 will be used by both peers, each endpoint MUST - // send a connection preface as a final confirmation ... The server - // connection - // preface consists of a potentially empty SETTINGS frame. - - // Load the server settings from the records.config / RecordsConfig.cc - // settings. - Http2ConnectionSettings configured_settings; - configured_settings.settings_from_configs(); - configured_settings.set(HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, _adjust_concurrent_stream()); - - send_settings_frame(configured_settings); - - if (server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) > HTTP2_INITIAL_WINDOW_SIZE) { - send_window_update_frame(0, server_settings.get(HTTP2_SETTINGS_INITIAL_WINDOW_SIZE) - HTTP2_INITIAL_WINDOW_SIZE); - } - - break; - } - // Finalize HTTP/2 Connection case HTTP2_SESSION_EVENT_FINI: { SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); diff --git a/proxy/http2/Http2ConnectionState.h b/proxy/http2/Http2ConnectionState.h index b79464ddbbd..da57fcbc0f1 100644 --- a/proxy/http2/Http2ConnectionState.h +++ b/proxy/http2/Http2ConnectionState.h @@ -89,7 +89,8 @@ class Http2ConnectionState : public Continuation Http2ConnectionSettings server_settings; Http2ConnectionSettings client_settings; - void init(); + void init(Http2ClientSession *ssn); + void send_connection_preface(); void destroy(); // Event handlers