src: Output debug data in GOAWAY in printable ascii

Non printable ascii is printed as ".".
This commit is contained in:
Tatsuhiro Tsujikawa 2014-03-31 23:17:51 +09:00
parent 6afb7442b5
commit b143039b60
1 changed files with 21 additions and 2 deletions

View File

@ -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<unsigned int>(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();