From f0b64ece629e66590d2f6964d3f3102fc1cf11b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 27 Feb 2020 16:27:34 +0100 Subject: Use specific error when HTTP/2 receives HTTP/1 response --- src/gun_http2.erl | 9 +++++++-- test/rfc7540_SUITE.erl | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gun_http2.erl b/src/gun_http2.erl index 3587466..64850fa 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -163,8 +163,13 @@ parse(Data, State0=#http2_state{status=preface, http2_machine=HTTP2Machine}, %% Any error in the preface is converted to this specific error %% to make debugging the problem easier (it's the server's fault). _ -> - {connection_error(State0, {connection_error, protocol_error, - 'Invalid connection preface received. (RFC7540 3.5)'}), EvHandlerState0} + Reason = case Data of + <<"HTTP/1",_/bits>> -> + 'Invalid connection preface received. Appears to be an HTTP/1 response? (RFC7540 3.5)'; + _ -> + 'Invalid connection preface received. (RFC7540 3.5)' + end, + {connection_error(State0, {connection_error, protocol_error, Reason}), EvHandlerState0} end; parse(Data, State0=#http2_state{status=Status, http2_machine=HTTP2Machine, streams=Streams}, EvHandler, EvHandlerState0) -> diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl index 76b4895..44794ef 100644 --- a/test/rfc7540_SUITE.erl +++ b/test/rfc7540_SUITE.erl @@ -111,7 +111,7 @@ prior_knowledge_preface_http1(_) -> handshake_completed = receive_from(OriginPid), receive {gun_down, ConnPid, http2, {error, {connection_error, protocol_error, - 'Invalid connection preface received. (RFC7540 3.5)'}}, []} -> + 'Invalid connection preface received. Appears to be an HTTP/1 response? (RFC7540 3.5)'}}, []} -> gun:close(ConnPid); Msg -> error({unexpected_msg, Msg}) @@ -138,7 +138,7 @@ prior_knowledge_preface_http1_await(_) -> {ok, http2} = gun:await_up(ConnPid), handshake_completed = receive_from(OriginPid), {error, {down, {shutdown, {error, {connection_error, protocol_error, - 'Invalid connection preface received. (RFC7540 3.5)'}}}}} + 'Invalid connection preface received. Appears to be an HTTP/1 response? (RFC7540 3.5)'}}}}} = gun:await(ConnPid, make_ref()), gun:close(ConnPid). -- cgit v1.2.3