nghttpx: Log transmission and reception of GOAWAY

This commit is contained in:
Tatsuhiro Tsujikawa 2014-07-12 23:30:13 +09:00
parent c4d2639ed8
commit bb47484667
4 changed files with 56 additions and 24 deletions

View File

@ -304,25 +304,6 @@ const char* frame_name_ansi_esc(print_type ptype)
} }
} // namespace } // 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 { namespace {
void print_frame(print_type ptype, const nghttp2_frame *frame) void print_frame(print_type ptype, const nghttp2_frame *frame)
{ {
@ -418,7 +399,7 @@ void print_frame(print_type ptype, const nghttp2_frame *frame)
strstatus(frame->goaway.error_code), strstatus(frame->goaway.error_code),
frame->goaway.error_code, frame->goaway.error_code,
static_cast<unsigned int>(frame->goaway.opaque_data_len), static_cast<unsigned int>(frame->goaway.opaque_data_len),
ascii_dump(frame->goaway.opaque_data, util::ascii_dump(frame->goaway.opaque_data,
frame->goaway.opaque_data_len).c_str()); frame->goaway.opaque_data_len).c_str());
break; break;
case NGHTTP2_WINDOW_UPDATE: case NGHTTP2_WINDOW_UPDATE:

View File

@ -447,6 +447,19 @@ int on_frame_recv_callback
return NGHTTP2_ERR_CALLBACK_FAILURE; return NGHTTP2_ERR_CALLBACK_FAILURE;
} }
break; 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: default:
break; break;
} }
@ -491,11 +504,28 @@ int on_frame_send_callback(nghttp2_session* session,
verbose_on_frame_send_callback(session, frame, user_data); verbose_on_frame_send_callback(session, frame, user_data);
} }
auto upstream = static_cast<Http2Upstream*>(user_data); auto upstream = static_cast<Http2Upstream*>(user_data);
if(frame->hd.type == NGHTTP2_SETTINGS &&
(frame->hd.flags & NGHTTP2_FLAG_ACK) == 0) { switch(frame->hd.type) {
if(upstream->start_settings_timer() != 0) { case NGHTTP2_SETTINGS:
if((frame->hd.flags & NGHTTP2_FLAG_ACK) == 0 &&
upstream->start_settings_timer() != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE; 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; return 0;
} }

View File

@ -599,6 +599,23 @@ int reopen_log_file(const char *path)
return fd; 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 util
} // namespace nghttp2 } // namespace nghttp2

View File

@ -483,6 +483,10 @@ bool numeric_host(const char *hostname);
// opened file if it succeeds, or -1. // opened file if it succeeds, or -1.
int reopen_log_file(const char *path); 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 util
} // namespace nghttp2 } // namespace nghttp2