From b143039b6065b6ba9a28cd07098c6361a03020c8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 31 Mar 2014 23:17:51 +0900 Subject: [PATCH] src: Output debug data in GOAWAY in printable ascii Non printable ascii is printed as ".". --- src/app_helper.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app_helper.cc b/src/app_helper.cc index dd4dc5a6..e29e37f6 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -325,6 +325,25 @@ 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) { @@ -431,8 +450,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), - util::format_hex(frame->goaway.opaque_data, - frame->goaway.opaque_data_len).c_str()); + ascii_dump(frame->goaway.opaque_data, + frame->goaway.opaque_data_len).c_str()); break; case NGHTTP2_WINDOW_UPDATE: print_frame_attr_indent();