diff options
author | Loïc Hoguin <[email protected]> | 2019-07-25 10:25:06 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-07-25 10:25:06 +0200 |
commit | 9e73a972b73a67dc5b8f23f99061f20713148e4e (patch) | |
tree | d078bd60185cdd7f7d5c28f4408e4e41c5a032bc | |
parent | 3d1e3c9e6e779bca839b86717adb2487b4a1c2c6 (diff) | |
download | gun-9e73a972b73a67dc5b8f23f99061f20713148e4e.tar.gz gun-9e73a972b73a67dc5b8f23f99061f20713148e4e.tar.bz2 gun-9e73a972b73a67dc5b8f23f99061f20713148e4e.zip |
Fix missing response_end event for HTTP/1.0 body_close
-rw-r--r-- | src/gun_http.erl | 7 | ||||
-rw-r--r-- | test/event_SUITE.erl | 23 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl index 738b6e9..08a287c 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -404,8 +404,13 @@ send_data_if_alive(_, State, _) -> State. %% @todo Use Reason. -close(_, State=#http_state{in=body_close, streams=[_|Tail]}, _, EvHandlerState) -> +close(_, State=#http_state{in=body_close, streams=[#stream{ref=StreamRef, reply_to=ReplyTo}|Tail]}, + EvHandler, EvHandlerState0) -> _ = send_data_if_alive(<<>>, State, fin), + EvHandlerState = EvHandler:response_end(#{ + stream_ref => StreamRef, + reply_to => ReplyTo + }, EvHandlerState0), {close_streams(Tail), EvHandlerState}; close(_, #http_state{streams=Streams}, _, EvHandlerState) -> {close_streams(Streams), EvHandlerState}. diff --git a/test/event_SUITE.erl b/test/event_SUITE.erl index d043a11..3535513 100644 --- a/test/event_SUITE.erl +++ b/test/event_SUITE.erl @@ -30,13 +30,15 @@ all() -> groups() -> Tests = ct_helper:all(?MODULE), + %% Some tests are written only for HTTP/1.0. + HTTP10Tests = [T || T <- Tests, lists:sublist(atom_to_list(T), 7) =:= "http10_"], %% Push is not possible over HTTP/1.1. PushTests = [T || T <- Tests, lists:sublist(atom_to_list(T), 5) =:= "push_"], %% We currently do not support Websocket over HTTP/2. WsTests = [T || T <- Tests, lists:sublist(atom_to_list(T), 3) =:= "ws_"], [ {http, [parallel], Tests -- [cancel_remote|PushTests]}, - {http2, [parallel], Tests -- [protocol_changed|WsTests]} + {http2, [parallel], (Tests -- [protocol_changed|WsTests]) -- HTTP10Tests} ]. init_per_suite(Config) -> @@ -475,6 +477,25 @@ do_response_end(Config, EventName, Path) -> } = do_receive_event(EventName), gun:close(Pid). +http10_response_end_body_close(Config) -> + doc("Confirm that the request_headers event callback is called " + "when using HTTP/1.0 and the content-length header is not set."), + OriginPort = config(tcp_origin_port, Config), + Opts = #{ + event_handler => {?MODULE, self()}, + http_opts => #{version => 'HTTP/1.0'}, + protocols => [config(name, config(tc_group_properties, Config))] + }, + {ok, Pid} = gun:open("localhost", OriginPort, Opts), + {ok, _} = gun:await_up(Pid), + StreamRef = gun:get(Pid, "/stream"), + ReplyTo = self(), + #{ + stream_ref := StreamRef, + reply_to := ReplyTo + } = do_receive_event(response_end), + gun:close(Pid). + ws_upgrade(Config) -> doc("Confirm that the ws_upgrade event callback is called."), {ok, Pid, _} = do_gun_open(Config), |