mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 04:10:24 +00:00
Improve some early_error tests
This commit is contained in:
parent
28aee1f272
commit
1a9e62ae2a
2 changed files with 18 additions and 13 deletions
|
@ -290,21 +290,20 @@ no_resp_body(Config) ->
|
|||
end.
|
||||
|
||||
early_error(Config) ->
|
||||
case config(protocol, Config) of
|
||||
http -> do_early_error(Config);
|
||||
http2 -> doc("The callback early_error/5 is not currently used for HTTP/2.")
|
||||
end.
|
||||
|
||||
do_early_error(Config) ->
|
||||
doc("Confirm metrics are correct for an early_error response."),
|
||||
%% Perform a malformed GET request.
|
||||
ConnPid = gun_open(Config),
|
||||
Ref = gun:get(ConnPid, "/", [
|
||||
%% We must use different solutions to hit early_error with a stream_error
|
||||
%% reason in both protocols.
|
||||
{Method, Headers, Status, Error} = case config(protocol, Config) of
|
||||
http -> {<<"GET">>, [{<<"host">>, <<"host:port">>}], 400, protocol_error};
|
||||
http2 -> {<<"TRACE">>, [], 501, no_error}
|
||||
end,
|
||||
Ref = gun:request(ConnPid, Method, "/", [
|
||||
{<<"accept-encoding">>, <<"gzip">>},
|
||||
{<<"host">>, <<"host:port">>},
|
||||
{<<"x-test-pid">>, pid_to_list(self())}
|
||||
]),
|
||||
{response, fin, 400, RespHeaders} = gun:await(ConnPid, Ref),
|
||||
|Headers], <<>>),
|
||||
{response, fin, Status, RespHeaders} = gun:await(ConnPid, Ref),
|
||||
gun:close(ConnPid),
|
||||
%% Receive the metrics and validate them.
|
||||
receive
|
||||
|
@ -314,9 +313,9 @@ do_early_error(Config) ->
|
|||
ref := _,
|
||||
pid := From,
|
||||
streamid := 1,
|
||||
reason := {stream_error, protocol_error, _},
|
||||
reason := {stream_error, Error, _},
|
||||
partial_req := #{},
|
||||
resp_status := 400,
|
||||
resp_status := Status,
|
||||
resp_headers := ExpectedRespHeaders,
|
||||
early_error_time := _,
|
||||
resp_body_length := 0
|
||||
|
@ -331,7 +330,7 @@ do_early_error(Config) ->
|
|||
early_error_request_line(Config) ->
|
||||
case config(protocol, Config) of
|
||||
http -> do_early_error_request_line(Config);
|
||||
http2 -> doc("The callback early_error/5 is not currently used for HTTP/2.")
|
||||
http2 -> doc("There are no request lines in HTTP/2.")
|
||||
end.
|
||||
|
||||
do_early_error_request_line(Config) ->
|
||||
|
|
|
@ -98,6 +98,12 @@ crash_in_init(Config) ->
|
|||
Pid = receive {Self, P, init, _, _, _} -> P after 1000 -> error(timeout) end,
|
||||
%% Confirm terminate/3 is NOT called. We have no state to give to it.
|
||||
receive {Self, Pid, terminate, _, _, _} -> error(terminate) after 1000 -> ok end,
|
||||
%% Confirm early_error/5 is called in HTTP/1.1's case.
|
||||
%% HTTP/2 does not send a response back so there is no early_error call.
|
||||
case config(protocol, Config) of
|
||||
http -> receive {Self, Pid, early_error, _, _, _, _, _} -> ok after 1000 -> error(timeout) end;
|
||||
http2 -> ok
|
||||
end,
|
||||
%% Receive a 500 error response.
|
||||
case gun:await(ConnPid, Ref) of
|
||||
{response, fin, 500, _} -> ok;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue