diff options
author | Daniel Stenberg <daniel@haxx.se> | 2016-04-01 20:42:25 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2016-04-02 16:27:30 +0200 |
commit | eca93542d6050ea66dcc4738b2bf03e076ff2e9d (patch) | |
tree | 8f08b710b287ae76a2e951ea3347189eead2a00d /lib | |
parent | 2aaa63b5551219d7cb85024f082028b87350f5e8 (diff) |
http2: make use of the nghttp2 error callback
It offers extra info from nghttp2 in certain error cases. Like for
example when trying prior-knowledge http2 on a server that doesn't speak
http2 at all. The error message is passed on as a verbose message to
libcurl.
Discussed in #722
The error callback was added in nghttp2 1.9.0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http2.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/http2.c b/lib/http2.c index 13f83947c..58274157b 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -46,6 +46,14 @@ #error too old nghttp2 version, upgrade! #endif +#if (NGHTTP2_VERSION_NUM >= 0x010900) +/* nghttp2_session_callbacks_set_error_callback is present in nghttp2 1.9.0 or + later */ +#define NGHTTP2_HAS_ERROR_CALLBACK 1 +#else +#define nghttp2_session_callbacks_set_error_callback(x,y) +#endif + /* * Curl_http2_init_state() is called when the easy handle is created and * allows for HTTP/2 specific init of state. @@ -912,6 +920,19 @@ static nghttp2_settings_entry settings[] = { #define H2_BUFSIZE 32768 +#ifdef NGHTTP2_HAS_ERROR_CALLBACK +static int error_callback(nghttp2_session *session, + const char *msg, + size_t len, + void *userp) +{ + struct connectdata *conn = (struct connectdata *)userp; + (void)session; + infof(conn->data, "http2 error: %.*s\n", len, msg); + return 0; +} +#endif + /* * Initialize nghttp2 for a Curl connection */ @@ -961,6 +982,8 @@ CURLcode Curl_http2_init(struct connectdata *conn) /* nghttp2_on_header_callback */ nghttp2_session_callbacks_set_on_header_callback(callbacks, on_header); + nghttp2_session_callbacks_set_error_callback(callbacks, error_callback); + /* The nghttp2 session is not yet setup, do it */ rc = nghttp2_session_client_new(&conn->proto.httpc.h2, callbacks, conn); |