Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: improve nghttp2 error callback #47840

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ Http2Session::Callbacks::Callbacks(bool kHasGetPaddingCallback) {
callbacks_, OnFrameNotSent);
nghttp2_session_callbacks_set_on_invalid_header_callback2(
callbacks_, OnInvalidHeader);
nghttp2_session_callbacks_set_error_callback(
callbacks_, OnNghttpError);
nghttp2_session_callbacks_set_error_callback2(callbacks_, OnNghttpError);
nghttp2_session_callbacks_set_send_data_callback(
callbacks_, OnSendData);
nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(
Expand Down Expand Up @@ -1257,21 +1256,18 @@ ssize_t Http2Session::OnSelectPadding(nghttp2_session* handle,
return padding;
}

#define BAD_PEER_MESSAGE "Remote peer returned unexpected data while we " \
"expected SETTINGS frame. Perhaps, peer does not " \
"support HTTP/2 properly."

// We use this currently to determine when an attempt is made to use the http2
// protocol with a non-http2 peer.
int Http2Session::OnNghttpError(nghttp2_session* handle,
int lib_error_code,
const char* message,
size_t len,
void* user_data) {
// Unfortunately, this is currently the only way for us to know if
// the session errored because the peer is not an http2 peer.
Http2Session* session = static_cast<Http2Session*>(user_data);
Debug(session, "Error '%s'", message);
if (strncmp(message, BAD_PEER_MESSAGE, len) == 0) {
if (lib_error_code == NGHTTP2_ERR_SETTINGS_EXPECTED) {
Environment* env = session->env();
Isolate* isolate = env->isolate();
HandleScope scope(isolate);
Expand Down
10 changes: 5 additions & 5 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,11 @@ class Http2Session : public AsyncWrap,
const nghttp2_frame* frame,
size_t maxPayloadLen,
void* user_data);
static int OnNghttpError(
nghttp2_session* session,
const char* message,
size_t len,
void* user_data);
static int OnNghttpError(nghttp2_session* session,
int lib_error_code,
const char* message,
size_t len,
void* user_data);
static int OnSendData(
nghttp2_session* session,
nghttp2_frame* frame,
Expand Down