diff --git a/src/app_helper.cc b/src/app_helper.cc index 336fa013..756fa519 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -304,25 +304,6 @@ const char* frame_name_ansi_esc(print_type ptype) } } // namespace -namespace { -std::string ascii_dump(const uint8_t *data, size_t len) -{ - std::string res; - - for(size_t i = 0; i < len; ++i) { - auto c = data[i]; - - if(c >= 0x20 && c < 0x7f) { - res += c; - } else { - res += "."; - } - } - - return res; -} -} // namespace - namespace { void print_frame(print_type ptype, const nghttp2_frame *frame) { @@ -418,8 +399,8 @@ void print_frame(print_type ptype, const nghttp2_frame *frame) strstatus(frame->goaway.error_code), frame->goaway.error_code, static_cast(frame->goaway.opaque_data_len), - ascii_dump(frame->goaway.opaque_data, - frame->goaway.opaque_data_len).c_str()); + util::ascii_dump(frame->goaway.opaque_data, + frame->goaway.opaque_data_len).c_str()); break; case NGHTTP2_WINDOW_UPDATE: print_frame_attr_indent(); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 20f87908..a7c89a3b 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -447,6 +447,19 @@ int on_frame_recv_callback return NGHTTP2_ERR_CALLBACK_FAILURE; } break; + case NGHTTP2_GOAWAY: + if(LOG_ENABLED(INFO)) { + auto debug_data = util::ascii_dump(frame->goaway.opaque_data, + frame->goaway.opaque_data_len); + + ULOG(INFO, upstream) << "GOAWAY received: last-stream-id=" + << frame->goaway.last_stream_id + << ", error_code=" + << frame->goaway.error_code + << ", debug_data=" + << debug_data; + } + break; default: break; } @@ -491,11 +504,28 @@ int on_frame_send_callback(nghttp2_session* session, verbose_on_frame_send_callback(session, frame, user_data); } auto upstream = static_cast(user_data); - if(frame->hd.type == NGHTTP2_SETTINGS && - (frame->hd.flags & NGHTTP2_FLAG_ACK) == 0) { - if(upstream->start_settings_timer() != 0) { + + switch(frame->hd.type) { + case NGHTTP2_SETTINGS: + if((frame->hd.flags & NGHTTP2_FLAG_ACK) == 0 && + upstream->start_settings_timer() != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; } + break; + case NGHTTP2_GOAWAY: + if(LOG_ENABLED(INFO)) { + auto debug_data = util::ascii_dump(frame->goaway.opaque_data, + frame->goaway.opaque_data_len); + + ULOG(INFO, upstream) << "Sending GOAWAY: last-stream-id=" + << frame->goaway.last_stream_id + << ", error_code=" + << frame->goaway.error_code + << ", debug_data=" + << debug_data; + } + break; } return 0; } diff --git a/src/util.cc b/src/util.cc index fdc96699..744f57b9 100644 --- a/src/util.cc +++ b/src/util.cc @@ -599,6 +599,23 @@ int reopen_log_file(const char *path) return fd; } +std::string ascii_dump(const uint8_t *data, size_t len) +{ + std::string res; + + for(size_t i = 0; i < len; ++i) { + auto c = data[i]; + + if(c >= 0x20 && c < 0x7f) { + res += c; + } else { + res += "."; + } + } + + return res; +} + } // namespace util } // namespace nghttp2 diff --git a/src/util.h b/src/util.h index 0f7771c6..c7cd501f 100644 --- a/src/util.h +++ b/src/util.h @@ -483,6 +483,10 @@ bool numeric_host(const char *hostname); // opened file if it succeeds, or -1. int reopen_log_file(const char *path); +// Returns ASCII dump of |data| of length |len|. Only ASCII printable +// characters are preserved. Other characters are replaced with ".". +std::string ascii_dump(const uint8_t *data, size_t len); + } // namespace util } // namespace nghttp2