Add nghttp2_http2_strerror() to return HTTP/2 error code string

This commit is contained in:
Tatsuhiro Tsujikawa 2016-02-29 23:09:15 +09:00
parent 478fde5fef
commit a21c87d11c
4 changed files with 49 additions and 39 deletions

View File

@ -49,6 +49,7 @@ APIDOCS= \
nghttp2_hd_inflate_hd.rst \ nghttp2_hd_inflate_hd.rst \
nghttp2_hd_inflate_new.rst \ nghttp2_hd_inflate_new.rst \
nghttp2_hd_inflate_new2.rst \ nghttp2_hd_inflate_new2.rst \
nghttp2_http2_strerror.rst \
nghttp2_is_fatal.rst \ nghttp2_is_fatal.rst \
nghttp2_nv_compare_name.rst \ nghttp2_nv_compare_name.rst \
nghttp2_option_del.rst \ nghttp2_option_del.rst \

View File

@ -3224,6 +3224,16 @@ nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen,
*/ */
NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code); NGHTTP2_EXTERN const char *nghttp2_strerror(int lib_error_code);
/**
* @function
*
* Returns string representation of HTTP/2 error code |error_code|
* (e.g., ``PROTOCOL_ERROR`` is returned if ``error_code ==
* NGHTTP2_PROTOCOL_ERROR``). If string representation is unknown for
* given |error_code|, this function returns string ``unknown``.
*/
NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code);
/** /**
* @function * @function
* *

View File

@ -451,3 +451,38 @@ uint8_t *nghttp2_cpymem(uint8_t *dest, const void *src, size_t len) {
return dest + len; return dest + len;
} }
const char *nghttp2_http2_strerror(uint32_t error_code) {
switch (error_code) {
case NGHTTP2_NO_ERROR:
return "NO_ERROR";
case NGHTTP2_PROTOCOL_ERROR:
return "PROTOCOL_ERROR";
case NGHTTP2_INTERNAL_ERROR:
return "INTERNAL_ERROR";
case NGHTTP2_FLOW_CONTROL_ERROR:
return "FLOW_CONTROL_ERROR";
case NGHTTP2_SETTINGS_TIMEOUT:
return "SETTINGS_TIMEOUT";
case NGHTTP2_STREAM_CLOSED:
return "STREAM_CLOSED";
case NGHTTP2_FRAME_SIZE_ERROR:
return "FRAME_SIZE_ERROR";
case NGHTTP2_REFUSED_STREAM:
return "REFUSED_STREAM";
case NGHTTP2_CANCEL:
return "CANCEL";
case NGHTTP2_COMPRESSION_ERROR:
return "COMPRESSION_ERROR";
case NGHTTP2_CONNECT_ERROR:
return "CONNECT_ERROR";
case NGHTTP2_ENHANCE_YOUR_CALM:
return "ENHANCE_YOUR_CALM";
case NGHTTP2_INADEQUATE_SECURITY:
return "INADEQUATE_SECURITY";
case NGHTTP2_HTTP_1_1_REQUIRED:
return "HTTP_1_1_REQUIRED";
default:
return "unknown";
}
}

View File

@ -62,43 +62,6 @@
namespace nghttp2 { namespace nghttp2 {
namespace {
const char *strstatus(uint32_t error_code) {
switch (error_code) {
case NGHTTP2_NO_ERROR:
return "NO_ERROR";
case NGHTTP2_PROTOCOL_ERROR:
return "PROTOCOL_ERROR";
case NGHTTP2_INTERNAL_ERROR:
return "INTERNAL_ERROR";
case NGHTTP2_FLOW_CONTROL_ERROR:
return "FLOW_CONTROL_ERROR";
case NGHTTP2_SETTINGS_TIMEOUT:
return "SETTINGS_TIMEOUT";
case NGHTTP2_STREAM_CLOSED:
return "STREAM_CLOSED";
case NGHTTP2_FRAME_SIZE_ERROR:
return "FRAME_SIZE_ERROR";
case NGHTTP2_REFUSED_STREAM:
return "REFUSED_STREAM";
case NGHTTP2_CANCEL:
return "CANCEL";
case NGHTTP2_COMPRESSION_ERROR:
return "COMPRESSION_ERROR";
case NGHTTP2_CONNECT_ERROR:
return "CONNECT_ERROR";
case NGHTTP2_ENHANCE_YOUR_CALM:
return "ENHANCE_YOUR_CALM";
case NGHTTP2_INADEQUATE_SECURITY:
return "INADEQUATE_SECURITY";
case NGHTTP2_HTTP_1_1_REQUIRED:
return "HTTP_1_1_REQUIRED";
default:
return "UNKNOWN";
}
}
} // namespace
namespace { namespace {
const char *strsettingsid(int32_t id) { const char *strsettingsid(int32_t id) {
switch (id) { switch (id) {
@ -335,7 +298,7 @@ void print_frame(print_type ptype, const nghttp2_frame *frame) {
case NGHTTP2_RST_STREAM: case NGHTTP2_RST_STREAM:
print_frame_attr_indent(); print_frame_attr_indent();
fprintf(outfile, "(error_code=%s(0x%02x))\n", fprintf(outfile, "(error_code=%s(0x%02x))\n",
strstatus(frame->rst_stream.error_code), nghttp2_http2_strerror(frame->rst_stream.error_code),
frame->rst_stream.error_code); frame->rst_stream.error_code);
break; break;
case NGHTTP2_SETTINGS: case NGHTTP2_SETTINGS:
@ -364,7 +327,8 @@ void print_frame(print_type ptype, const nghttp2_frame *frame) {
print_frame_attr_indent(); print_frame_attr_indent();
fprintf(outfile, "(last_stream_id=%d, error_code=%s(0x%02x), " fprintf(outfile, "(last_stream_id=%d, error_code=%s(0x%02x), "
"opaque_data(%u)=[%s])\n", "opaque_data(%u)=[%s])\n",
frame->goaway.last_stream_id, strstatus(frame->goaway.error_code), frame->goaway.last_stream_id,
nghttp2_http2_strerror(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),
util::ascii_dump(frame->goaway.opaque_data, util::ascii_dump(frame->goaway.opaque_data,