diff --git a/src/chatterbox_ranch_protocol.erl b/src/chatterbox_ranch_protocol.erl index 3175a423..bc4996c7 100644 --- a/src/chatterbox_ranch_protocol.erl +++ b/src/chatterbox_ranch_protocol.erl @@ -18,7 +18,7 @@ start_link(Ref, Socket, Transport, Opts) -> init(Ref, Socket, T, Opts) -> ok = ranch:accept_ack(Ref), Http2Settings = proplists:get_value(http2_settings, Opts, chatterbox:settings(server)), - http2_connection:become({transport(T), Socket}, Http2Settings). + h2_connection:become({transport(T), Socket}, Http2Settings). transport(ranch_ssl) -> ssl; diff --git a/src/chatterbox_static_content_handler.erl b/src/chatterbox_static_content_handler.erl index cbe98fc9..8f2bbe4d 100644 --- a/src/chatterbox_static_content_handler.erl +++ b/src/chatterbox_static_content_handler.erl @@ -62,8 +62,8 @@ handle(ConnPid, StreamId, Headers, _ReqBody) -> ResponseHeaders = [ {<<":status">>,<<"403">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, <<"No soup for you!">>), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, <<"No soup for you!">>), ok; {true, false} -> Ext = filename:extension(File), @@ -83,10 +83,10 @@ handle(ConnPid, StreamId, Headers, _ReqBody) -> {<<"content-type">>, MimeType} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - case {MimeType, http2_connection:is_push(ConnPid)} of + case {MimeType, h2_connection:is_push(ConnPid)} of {<<"text/html">>, true} -> %% Search Data for resources to push {ok, RE} = re:compile(" NewStreams = lists:foldl(fun(R, Acc) -> - NewStreamId = http2_connection:new_stream(ConnPid), - PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>>), - http2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders), + NewStreamId = h2_connection:new_stream(ConnPid), + PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>> + ), + h2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders), [{NewStreamId, PHeaders}|Acc] end, [], @@ -117,14 +118,14 @@ handle(ConnPid, StreamId, Headers, _ReqBody) -> _ -> ok end, - http2_connection:send_body(ConnPid, StreamId, Data), + h2_connection:send_body(ConnPid, StreamId, Data), ok; {false, false} -> ResponseHeaders = [ {<<":status">>,<<"404">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, <<"No soup for you!">>), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, <<"No soup for you!">>), ok end, ok. diff --git a/src/chatterbox_static_stream.erl b/src/chatterbox_static_stream.erl index 4de7e02b..31888c36 100644 --- a/src/chatterbox_static_stream.erl +++ b/src/chatterbox_static_stream.erl @@ -2,7 +2,7 @@ -include("http2.hrl"). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -99,7 +99,7 @@ on_request_end_stream(State=#cb_static{connection_pid=ConnPid, {<<"content-type">>, MimeType} ], - case {MimeType, http2_connection:is_push(ConnPid)} of + case {MimeType, h2_connection:is_push(ConnPid)} of {<<"text/html">>, true} -> %% Search Data for resources to push {ok, RE} = re:compile(" - NewStreamId = http2_connection:new_stream(ConnPid), - PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>>), - http2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders), + NewStreamId = h2_connection:new_stream(ConnPid), + PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>> + ), + h2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders), [{NewStreamId, PHeaders}|Acc] end, [], @@ -149,11 +150,11 @@ on_request_end_stream(State=#cb_static{connection_pid=ConnPid, case {Method, HeadersToSend, BodyToSend} of {<<"HEAD">>, _, _} -> - http2_connection:send_headers(ConnPid, StreamId, HeadersToSend, [{send_end_stream, true}]); + h2_connection:send_headers(ConnPid, StreamId, HeadersToSend, [{send_end_stream, true}]); %%{<<"GET">>, _, _} -> _ -> - http2_connection:send_headers(ConnPid, StreamId, HeadersToSend), - http2_connection:send_body(ConnPid, StreamId, BodyToSend) + h2_connection:send_headers(ConnPid, StreamId, HeadersToSend), + h2_connection:send_body(ConnPid, StreamId, BodyToSend) end, {ok, State}. diff --git a/src/chatterbox_sup.erl b/src/chatterbox_sup.erl index 59375eb5..6d88f2a7 100644 --- a/src/chatterbox_sup.erl +++ b/src/chatterbox_sup.erl @@ -35,8 +35,8 @@ init([]) -> {ok, ListenSocket} = gen_tcp:listen(Port, Options), Restart = {simple_one_for_one, 60, 3600}, Children = [{socket, - {http2_connection, start_server_link, [{Transport, ListenSocket}, SSLOptions, Http2Settings]}, - temporary, 1000, worker, [http2_socket]}], + {h2_connection, start_server_link, [{Transport, ListenSocket}, SSLOptions, Http2Settings]}, + temporary, 1000, worker, [h2_connection]}], {ok, {Restart, Children}}. start_socket() -> diff --git a/src/http2_client.erl b/src/h2_client.erl similarity index 85% rename from src/http2_client.erl rename to src/h2_client.erl index 93c1d98f..e1008856 100644 --- a/src/http2_client.erl +++ b/src/h2_client.erl @@ -1,5 +1,4 @@ --module(http2_client). - +-module(h2_client). -include("http2.hrl"). %% Today's the day! We need to turn this gen_server into a gen_fsm @@ -106,33 +105,33 @@ start_link(Transport, Host, Port, SSLOptions) -> http -> gen_tcp; https -> ssl end, - http2_connection:start_client_link(NewT, Host, Port, SSLOptions, chatterbox:settings(client)). + h2_connection:start_client_link(NewT, Host, Port, SSLOptions, chatterbox:settings(client)). start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions) -> - http2_connection:start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions, chatterbox:settings(client)). + h2_connection:start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions, chatterbox:settings(client)). -spec stop(pid()) -> ok. stop(Pid) -> - http2_connection:stop(Pid). + h2_connection:stop(Pid). sync_request(CliPid, Headers, Body) -> - StreamId = http2_connection:new_stream(CliPid), - http2_connection:send_headers(CliPid, StreamId, Headers), - http2_connection:send_body(CliPid,StreamId,Body), + StreamId = h2_connection:new_stream(CliPid), + h2_connection:send_headers(CliPid, StreamId, Headers), + h2_connection:send_body(CliPid,StreamId,Body), receive {'END_STREAM', StreamId} -> - http2_connection:get_response(CliPid, StreamId) + h2_connection:get_response(CliPid, StreamId) after 5000 -> {error, timeout} end. send_request(CliPid, Headers, Body) -> - StreamId = http2_connection:new_stream(CliPid), - http2_connection:send_headers(CliPid, StreamId, Headers), - http2_connection:send_body(CliPid,StreamId,Body), + StreamId = h2_connection:new_stream(CliPid), + h2_connection:send_headers(CliPid, StreamId, Headers), + h2_connection:send_body(CliPid,StreamId,Body), {ok, StreamId}. -spec get_response(pid(), stream_id()) -> {ok, {hpack:header(), iodata()}} | {error, term()}. get_response(CliPid, StreamId) -> - http2_connection:get_response(CliPid, StreamId). + h2_connection:get_response(CliPid, StreamId). diff --git a/src/http2_connection.erl b/src/h2_connection.erl similarity index 93% rename from src/http2_connection.erl rename to src/h2_connection.erl index 888ea6b4..178de2c3 100644 --- a/src/http2_connection.erl +++ b/src/h2_connection.erl @@ -1,8 +1,6 @@ --module(http2_connection). - --behaviour(gen_fsm). - +-module(h2_connection). -include("http2.hrl"). +-behaviour(gen_fsm). %% Start/Stop API -export([ @@ -290,7 +288,7 @@ connected({frame, Frame}, #connection{}=Conn ) -> lager:debug("[~p][connected] {frame, ~p}", - [Conn#connection.type, http2_frame:format(Frame)]), + [Conn#connection.type, h2_frame:format(Frame)]), route_frame(Frame, Conn). %% The continuation state in entered after receiving a HEADERS frame @@ -307,7 +305,7 @@ continuation({frame, } }=Conn) -> lager:debug("[~p][continuation] [next] ~p", - [Conn#connection.type, http2_frame:format(Frame)]), + [Conn#connection.type, h2_frame:format(Frame)]), route_frame(Frame, Conn); continuation(_, Conn) -> go_away(?PROTOCOL_ERROR, Conn). @@ -361,12 +359,12 @@ route_frame({H, Payload}, encode_context=EncodeContext }=Conn) when H#frame_header.type == ?SETTINGS, - ?NOT_FLAG(H#frame_header.flags, ?FLAG_ACK) -> + ?NOT_FLAG((H#frame_header.flags), ?FLAG_ACK) -> lager:debug("[~p] Received SETTINGS", [Conn#connection.type]), %% Need a way of processing settings so I know which ones came in %% on this one payload. - case http2_frame_settings:validate(Payload) of + case h2_frame_settings:validate(Payload) of ok -> {settings, PList} = Payload, @@ -379,7 +377,7 @@ route_frame({H, Payload}, lager:debug("old IWS: ~p new IWS: ~p", [OldIWS, NewIWS]), NewIWS - OldIWS end, - NewPeerSettings = http2_frame_settings:overlay(PS, Payload), + NewPeerSettings = h2_frame_settings:overlay(PS, Payload), %% We've just got connection settings from a peer. He have a %% couple of jobs to do here w.r.t. flow control @@ -401,7 +399,7 @@ route_frame({H, Payload}, NewEncodeContext = hpack:new_max_table_size(HTS, EncodeContext), - socksend(Conn, http2_frame_settings:ack()), + socksend(Conn, h2_frame_settings:ack()), lager:debug("[~p] Sent Settings ACK", [Conn#connection.type]), {next_state, connected, Conn#connection{ @@ -414,7 +412,6 @@ route_frame({H, Payload}, }}; {error, Code} -> go_away(Code, Conn) - end; %% This is the case where we got an ACK, so dequeue settings we're @@ -428,7 +425,7 @@ route_frame({H, _Payload}, } }=Conn) when H#frame_header.type == ?SETTINGS, - ?IS_FLAG(H#frame_header.flags, ?FLAG_ACK) -> + ?IS_FLAG((H#frame_header.flags), ?FLAG_ACK) -> lager:debug("[~p] Received SETTINGS ACK", [Conn#connection.type]), case queue:out(SS) of @@ -507,8 +504,8 @@ route_frame(F={H=#frame_header{ %% Make window size great again lager:info("[~p] Stream ~p WindowUpdate ~p", [Conn#connection.type, StreamId, L]), - http2_frame_window_update:send(Conn#connection.socket, - L, StreamId), + h2_frame_window_update:send(Conn#connection.socket, + L, StreamId), send_window_update(self(), L); _Tried -> ok @@ -558,8 +555,8 @@ route_frame({#frame_header{type=?HEADERS}=FH, _Payload}=Frame, self(), Conn#connection.stream_callback_mod, Conn#connection.socket, - Conn#connection.peer_settings#settings.initial_window_size, - Conn#connection.self_settings#settings.initial_window_size, + (Conn#connection.peer_settings)#settings.initial_window_size, + (Conn#connection.self_settings)#settings.initial_window_size, Streams) of {error, ErrorCode, NewStream} -> rst_stream(NewStream, ErrorCode, Conn), @@ -583,8 +580,8 @@ route_frame({#frame_header{type=?HEADERS}=FH, _Payload}=Frame, #continuation_state{ type = ContinuationType, frames = queue:from_list([Frame]), - end_stream = ?IS_FLAG(FH#frame_header.flags, ?FLAG_END_STREAM), - end_headers = ?IS_FLAG(FH#frame_header.flags, ?FLAG_END_HEADERS), + end_stream = ?IS_FLAG((FH#frame_header.flags), ?FLAG_END_STREAM), + end_headers = ?IS_FLAG((FH#frame_header.flags), ?FLAG_END_HEADERS), stream_id = StreamId }, %% maybe_hpack/2 uses this #continuation_state to figure @@ -607,7 +604,7 @@ route_frame(F={H=#frame_header{ maybe_hpack(Cont#continuation_state{ frames=queue:in(F, CFQ), - end_headers=?IS_FLAG(H#frame_header.flags, ?FLAG_END_HEADERS) + end_headers=?IS_FLAG((H#frame_header.flags), ?FLAG_END_HEADERS) }, Conn); @@ -630,7 +627,7 @@ route_frame( }, Payload}, #connection{} = Conn) -> - EC = http2_frame_rst_stream:error_code(Payload), + EC = h2_frame_rst_stream:error_code(Payload), lager:debug("[~p] Received RST_STREAM (~p) for Stream ~p", [Conn#connection.type, EC, StreamId]), Streams = Conn#connection.streams, @@ -654,7 +651,7 @@ route_frame({H=#frame_header{ #connection{}=Conn) when H#frame_header.type == ?PUSH_PROMISE, Conn#connection.type == client -> - PSID = http2_frame_push_promise:promised_stream_id(Payload), + PSID = h2_frame_push_promise:promised_stream_id(Payload), lager:debug("[~p] Received PUSH_PROMISE Frame on Stream ~p for Stream ~p", [Conn#connection.type, StreamId, PSID]), @@ -675,15 +672,15 @@ route_frame({H=#frame_header{ NotifyPid, Conn#connection.stream_callback_mod, Conn#connection.socket, - Conn#connection.peer_settings#settings.initial_window_size, - Conn#connection.self_settings#settings.initial_window_size, + (Conn#connection.peer_settings)#settings.initial_window_size, + (Conn#connection.self_settings)#settings.initial_window_size, Streams), Continuation = #continuation_state{ stream_id=StreamId, type=push_promise, frames = queue:in(Frame, queue:new()), - end_headers=?IS_FLAG(H#frame_header.flags, ?FLAG_END_HEADERS), + end_headers=?IS_FLAG((H#frame_header.flags), ?FLAG_END_HEADERS), promised_id=PSID }, maybe_hpack(Continuation, @@ -708,16 +705,16 @@ route_frame({H, _Payload}, route_frame({H, Ping}, #connection{}=Conn) when H#frame_header.type == ?PING, - ?NOT_FLAG(#frame_header.flags, ?FLAG_ACK) -> + ?NOT_FLAG((#frame_header.flags), ?FLAG_ACK) -> lager:debug("[~p] Received PING", [Conn#connection.type]), - Ack = http2_frame_ping:ack(Ping), - socksend(Conn, http2_frame:to_binary(Ack)), + Ack = h2_frame_ping:ack(Ping), + socksend(Conn, h2_frame:to_binary(Ack)), {next_state, connected, Conn}; route_frame({H, _Payload}, #connection{}=Conn) when H#frame_header.type == ?PING, - ?IS_FLAG(H#frame_header.flags, ?FLAG_ACK) -> + ?IS_FLAG((H#frame_header.flags), ?FLAG_ACK) -> lager:debug("[~p] Received PING ACK", [Conn#connection.type]), {next_state, connected, Conn}; @@ -738,7 +735,7 @@ route_frame( #connection{ send_window_size=SWS }=Conn) -> - WSI = http2_frame_window_update:size_increment(Payload), + WSI = h2_frame_window_update:size_increment(Payload), lager:debug("[~p] Stream 0 Window Update: ~p", [Conn#connection.type, WSI]), NewSendWindow = SWS+WSI, @@ -754,7 +751,7 @@ route_frame( h2_stream_set:send_what_we_can( all, NewSendWindow, - Conn#connection.peer_settings#settings.max_frame_size, + (Conn#connection.peer_settings)#settings.max_frame_size, Streams ), lager:debug("[~p] and Connection Send Window now: ~p", @@ -772,7 +769,7 @@ route_frame( ) -> StreamId = FH#frame_header.stream_id, Streams = Conn#connection.streams, - WSI = http2_frame_window_update:size_increment(Payload), + WSI = h2_frame_window_update:size_increment(Payload), lager:debug("[~p] Received WINDOW_UPDATE Frame for Stream ~p", [Conn#connection.type, StreamId]), @@ -798,7 +795,7 @@ route_frame( = h2_stream_set:send_what_we_can( StreamId, SWS, - Conn#connection.peer_settings#settings.max_frame_size, + (Conn#connection.peer_settings)#settings.max_frame_size, h2_stream_set:upsert( h2_stream_set:increment_send_window_size(WSI, Stream), Streams) @@ -818,7 +815,7 @@ route_frame(Frame, #connection{}=Conn) -> lager:error("[~p] Frame condition not covered by pattern match", [Conn#connection.type]), lager:error("This is bad and you probably found a bug. Please open a github issue with this output:"), - lager:error("OOPS! " ++ http2_frame:format(Frame)), + lager:error("OOPS! " ++ h2_frame:format(Frame)), lager:error("OOPS! ~p", [Conn]), go_away(?PROTOCOL_ERROR, Conn). @@ -868,7 +865,7 @@ handle_event({send_window_update, Size}, recv_window_size=CRWS, socket=Socket }=Conn) -> - ok = http2_frame_window_update:send(Socket, Size, 0), + ok = h2_frame_window_update:send(Socket, Size, 0), {next_state, StateName, Conn#connection{ @@ -890,13 +887,13 @@ handle_event({send_headers, StreamId, Headers, Opts}, case h2_stream_set:type(Stream) of active -> {FramesToSend, NewContext} = - http2_frame_headers:to_frames(h2_stream_set:stream_id(Stream), - Headers, - EncodeContext, - Conn#connection.peer_settings#settings.max_frame_size, - StreamComplete - ), - [ sock:send(Socket, http2_frame:to_binary(Frame)) || Frame <- FramesToSend], + h2_frame_headers:to_frames(h2_stream_set:stream_id(Stream), + Headers, + EncodeContext, + (Conn#connection.peer_settings)#settings.max_frame_size, + StreamComplete + ), + [sock:send(Socket, h2_frame:to_binary(Frame)) || Frame <- FramesToSend], send_h(Stream, Headers), {next_state, StateName, Conn#connection{ @@ -930,7 +927,7 @@ handle_event({send_body, StreamId, Body, Opts}, h2_stream_set:send_what_we_can( StreamId, Conn#connection.send_window_size, - Conn#connection.peer_settings#settings.max_frame_size, + (Conn#connection.peer_settings)#settings.max_frame_size, h2_stream_set:upsert( h2_stream_set:update_data_queue(NewBody, BodyComplete, Stream), Conn#connection.streams)), @@ -963,19 +960,19 @@ handle_event({send_promise, StreamId, NewStreamId, Headers}, active -> %% TODO: This could be a series of frames, not just one {PromiseFrame, NewContext} = - http2_frame_push_promise:to_frame( - StreamId, - NewStreamId, - Headers, - OldContext - ), + h2_frame_push_promise:to_frame( + StreamId, + NewStreamId, + Headers, + OldContext + ), %% Send the PP Frame - Binary = http2_frame:to_binary(PromiseFrame), + Binary = h2_frame:to_binary(PromiseFrame), socksend(Conn, Binary), %% Get the promised stream rolling - http2_stream:send_pp(h2_stream_set:stream_pid(NewStream), Headers), + h2_stream:send_pp(h2_stream_set:stream_pid(NewStream), Headers), {next_state, StateName, Conn#connection{ @@ -1004,7 +1001,7 @@ handle_event({send_bin, Binary}, StateName, {next_state, StateName, Conn}; handle_event({send_frame, Frame}, StateName, #connection{} =Conn) -> - Binary = http2_frame:to_binary(Frame), + Binary = h2_frame:to_binary(Frame), socksend(Conn, Binary), {next_state, StateName, Conn}; handle_event(stop, _StateName, @@ -1184,10 +1181,10 @@ go_away(ErrorCode, #connection{ next_available_stream_id=NAS }=Conn) -> - GoAway = http2_frame_goaway:new(NAS, ErrorCode), - GoAwayBin = http2_frame:to_binary({#frame_header{ - stream_id=0 - }, GoAway}), + GoAway = h2_frame_goaway:new(NAS, ErrorCode), + GoAwayBin = h2_frame:to_binary({#frame_header{ + stream_id=0 + }, GoAway}), socksend(Conn, GoAwayBin), gen_fsm:send_event(self(), io_lib:format("GO_AWAY: ErrorCode ~p", [ErrorCode])), {next_state, closing, Conn}. @@ -1210,16 +1207,16 @@ rst_stream(Stream, ErrorCode, Conn) -> %% http2_stream's rst_stream will take care of letting us know %% this stream is closed and will send us a message to close the %% stream somewhere else - http2_stream:rst_stream(Pid, ErrorCode), + h2_stream:rst_stream(Pid, ErrorCode), {next_state, connected, Conn}; _ -> StreamId = h2_stream_set:stream_id(Stream), - RstStream = http2_frame_rst_stream:new(ErrorCode), - RstStreamBin = http2_frame:to_binary( - {#frame_header{ - stream_id=StreamId - }, - RstStream}), + RstStream = h2_frame_rst_stream:new(ErrorCode), + RstStreamBin = h2_frame:to_binary( + {#frame_header{ + stream_id=StreamId + }, + RstStream}), sock:send(Conn#connection.socket, RstStreamBin), {next_state, connected, Conn} end. @@ -1231,7 +1228,7 @@ send_settings(SettingsToSend, settings_sent=SS }=Conn) -> Ref = make_ref(), - Bin = http2_frame_settings:send(CurrentSettings, SettingsToSend), + Bin = h2_frame_settings:send(CurrentSettings, SettingsToSend), socksend(Conn, Bin), send_ack_timeout({Ref,SettingsToSend}), Conn#connection{ @@ -1368,7 +1365,7 @@ handle_socket_data(Data, %% further state references don't have one NewConn = Conn#connection{buffer=empty}, - case http2_frame:recv(ToParse) of + case h2_frame:recv(ToParse) of %% We got a full frame, ship it off to the FSM {ok, Frame, Rem} -> gen_fsm:send_event(self(), {frame, Frame}), @@ -1426,9 +1423,9 @@ maybe_hpack(Continuation, Conn) Continuation#continuation_state.stream_id, Conn#connection.streams ), - HeadersBin = http2_frame_headers:from_frames( - queue:to_list(Continuation#continuation_state.frames) - ), + HeadersBin = h2_frame_headers:from_frames( + queue:to_list(Continuation#continuation_state.frames) + ), case hpack:decode(HeadersBin, Conn#connection.decode_context) of {error, compression_error} -> go_away(?COMPRESSION_ERROR, Conn); diff --git a/src/http2_frame.erl b/src/h2_frame.erl similarity index 85% rename from src/http2_frame.erl rename to src/h2_frame.erl index 20bfa2db..8a734cac 100644 --- a/src/http2_frame.erl +++ b/src/h2_frame.erl @@ -1,4 +1,4 @@ --module(http2_frame). +-module(h2_frame). -include("http2.hrl"). @@ -150,25 +150,25 @@ read_payload({Transport, Socket}, Header=#frame_header{length=L}, Timeout) -> | {error, error_code()} | {error, stream_id(), error_code(), binary()}. read_binary_payload(Bin, Header = #frame_header{type=?DATA}) -> - http2_frame_data:read_binary(Bin, Header); + h2_frame_data:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?HEADERS}) -> - http2_frame_headers:read_binary(Bin, Header); + h2_frame_headers:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?PRIORITY}) -> - http2_frame_priority:read_binary(Bin, Header); + h2_frame_priority:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?RST_STREAM}) -> - http2_frame_rst_stream:read_binary(Bin, Header); + h2_frame_rst_stream:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?SETTINGS}) -> - http2_frame_settings:read_binary(Bin, Header); + h2_frame_settings:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?PUSH_PROMISE}) -> - http2_frame_push_promise:read_binary(Bin, Header); + h2_frame_push_promise:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?PING}) -> - http2_frame_ping:read_binary(Bin, Header); + h2_frame_ping:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?GOAWAY}) -> - http2_frame_goaway:read_binary(Bin, Header); + h2_frame_goaway:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?WINDOW_UPDATE}) -> - http2_frame_window_update:read_binary(Bin, Header); + h2_frame_window_update:read_binary(Bin, Header); read_binary_payload(Bin, Header = #frame_header{type=?CONTINUATION}) -> - http2_frame_continuation:read_binary(Bin, Header); + h2_frame_continuation:read_binary(Bin, Header); read_binary_payload(Bin, Header) -> read_unsupported_frame_binary(Bin, Header). @@ -182,25 +182,25 @@ read_unsupported_frame_binary(Bin, -spec format_payload(frame()) -> iodata(). format_payload({#frame_header{type=?DATA}, P}) -> - http2_frame_data:format(P); + h2_frame_data:format(P); format_payload({#frame_header{type=?HEADERS}, P}) -> - http2_frame_headers:format(P); + h2_frame_headers:format(P); format_payload({#frame_header{type=?PRIORITY}, P}) -> - http2_frame_priority:format(P); + h2_frame_priority:format(P); format_payload({#frame_header{type=?RST_STREAM}, P}) -> - http2_frame_rst_stream:format(P); + h2_frame_rst_stream:format(P); format_payload({#frame_header{type=?SETTINGS}, P}) -> - http2_frame_settings:format(P); + h2_frame_settings:format(P); format_payload({#frame_header{type=?PUSH_PROMISE}, P}) -> - http2_frame_push_promise:format(P); + h2_frame_push_promise:format(P); format_payload({#frame_header{type=?PING}, P}) -> - http2_frame_ping:format(P); + h2_frame_ping:format(P); format_payload({#frame_header{type=?GOAWAY}, P}) -> - http2_frame_goaway:format(P); + h2_frame_goaway:format(P); format_payload({#frame_header{type=?WINDOW_UPDATE}, P}) -> - http2_frame_window_update:format(P); + h2_frame_window_update:format(P); format_payload({#frame_header{type=?CONTINUATION}, P}) -> - http2_frame_continuation:format(P); + h2_frame_continuation:format(P); format_payload({_, _P}) -> "Unsupported Frame". @@ -238,16 +238,16 @@ payload_to_binary(P) -> Bin = case Type of - ?DATA -> http2_frame_data:to_binary(P); - ?HEADERS -> http2_frame_headers:to_binary(P); - ?PRIORITY -> http2_frame_priority:to_binary(P); - ?RST_STREAM -> http2_frame_rst_stream:to_binary(P); - ?SETTINGS -> http2_frame_settings:to_binary(P); - ?PUSH_PROMISE -> http2_frame_push_promise:to_binary(P); - ?PING -> http2_frame_ping:to_binary(P); - ?GOAWAY -> http2_frame_goaway:to_binary(P); - ?WINDOW_UPDATE -> http2_frame_window_update:to_binary(P); - ?CONTINUATION -> http2_frame_continuation:to_binary(P) + ?DATA -> h2_frame_data:to_binary(P); + ?HEADERS -> h2_frame_headers:to_binary(P); + ?PRIORITY -> h2_frame_priority:to_binary(P); + ?RST_STREAM -> h2_frame_rst_stream:to_binary(P); + ?SETTINGS -> h2_frame_settings:to_binary(P); + ?PUSH_PROMISE -> h2_frame_push_promise:to_binary(P); + ?PING -> h2_frame_ping:to_binary(P); + ?GOAWAY -> h2_frame_goaway:to_binary(P); + ?WINDOW_UPDATE -> h2_frame_window_update:to_binary(P); + ?CONTINUATION -> h2_frame_continuation:to_binary(P) end, {Type, Bin}. diff --git a/src/http2_frame_continuation.erl b/src/h2_frame_continuation.erl similarity index 94% rename from src/http2_frame_continuation.erl rename to src/h2_frame_continuation.erl index 2810852d..68c77f60 100644 --- a/src/http2_frame_continuation.erl +++ b/src/h2_frame_continuation.erl @@ -1,8 +1,6 @@ --module(http2_frame_continuation). - +-module(h2_frame_continuation). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ diff --git a/src/http2_frame_data.erl b/src/h2_frame_data.erl similarity index 94% rename from src/http2_frame_data.erl rename to src/h2_frame_data.erl index 2d0bdaee..9edc62a3 100644 --- a/src/http2_frame_data.erl +++ b/src/h2_frame_data.erl @@ -1,6 +1,6 @@ --module(http2_frame_data). - +-module(h2_frame_data). -include("http2.hrl"). +-behaviour(h2_frame). -export([ format/1, @@ -11,8 +11,6 @@ new/1 ]). --behaviour(http2_frame). - -record(data, { data :: iodata() }). @@ -48,7 +46,7 @@ read_binary(Bin, _H=#frame_header{length=0}) -> read_binary(Bin, H=#frame_header{length=L}) -> lager:debug("read_binary L: ~p, actually: ~p", [L, byte_size(Bin)]), <> = Bin, - case http2_padding:read_possibly_padded_payload(PayloadBin, H) of + case h2_padding:read_possibly_padded_payload(PayloadBin, H) of {error, Code} -> {error, Code}; Data -> diff --git a/src/http2_frame_goaway.erl b/src/h2_frame_goaway.erl similarity index 96% rename from src/http2_frame_goaway.erl rename to src/h2_frame_goaway.erl index a9ebb2c9..a3b3c69b 100644 --- a/src/http2_frame_goaway.erl +++ b/src/h2_frame_goaway.erl @@ -1,8 +1,6 @@ --module(http2_frame_goaway). - +-module(h2_frame_goaway). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ diff --git a/src/http2_frame_headers.erl b/src/h2_frame_headers.erl similarity index 92% rename from src/http2_frame_headers.erl rename to src/h2_frame_headers.erl index 030f6a35..522aaf80 100644 --- a/src/http2_frame_headers.erl +++ b/src/h2_frame_headers.erl @@ -1,8 +1,6 @@ --module(http2_frame_headers). - +-module(h2_frame_headers). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ @@ -51,15 +49,15 @@ read_binary(_, {error, 0, ?PROTOCOL_ERROR, <<>>}; read_binary(Bin, H = #frame_header{length=L}) -> <> = Bin, - case http2_padding:read_possibly_padded_payload(PayloadBin, H) of + case h2_padding:read_possibly_padded_payload(PayloadBin, H) of {error, Code} -> {error, 0, Code, Rem}; Data -> {Priority, PSID, HeaderFragment} = case is_priority(H) of true -> - {P, PRem} = http2_frame_priority:read_priority(Data), - PStream = http2_frame_priority:stream_id(P), + {P, PRem} = h2_frame_priority:read_priority(Data), + PStream = h2_frame_priority:stream_id(P), {P, PStream, PRem}; false -> {undefined, undefined, Data} @@ -108,20 +106,20 @@ to_binary(#headers{ undefined -> BF; _ -> - [http2_frame_priority:to_binary(P), BF] + [h2_frame_priority:to_binary(P), BF] end. -spec from_frames([http2_frame:frame()], binary()) -> binary(). from_frames([{#frame_header{type=?HEADERS},#headers{block_fragment=BF}}|Continuations])-> from_frames(Continuations, BF); from_frames([{#frame_header{type=?PUSH_PROMISE},PP}|Continuations])-> - BF = http2_frame_push_promise:block_fragment(PP), + BF = h2_frame_push_promise:block_fragment(PP), from_frames(Continuations, BF). from_frames([], Acc) -> Acc; from_frames([{#frame_header{type=?CONTINUATION},Cont}|Continuations], Acc) -> - BF = http2_frame_continuation:block_fragment(Cont), + BF = h2_frame_continuation:block_fragment(Cont), from_frames(Continuations, <>). -spec split(Binary::binary(), @@ -189,6 +187,6 @@ build_frames_(StreamId, [NextChunk|Rest], Acc) -> flags=0, length=byte_size(NextChunk) }, - http2_frame_continuation:new(NextChunk) + h2_frame_continuation:new(NextChunk) }, build_frames_(StreamId, Rest, [NextFrame|Acc]). diff --git a/src/http2_frame_ping.erl b/src/h2_frame_ping.erl similarity index 96% rename from src/http2_frame_ping.erl rename to src/h2_frame_ping.erl index 49d87bbb..b384ad51 100644 --- a/src/http2_frame_ping.erl +++ b/src/h2_frame_ping.erl @@ -1,8 +1,6 @@ --module(http2_frame_ping). - +-module(h2_frame_ping). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ diff --git a/src/http2_frame_priority.erl b/src/h2_frame_priority.erl similarity index 97% rename from src/http2_frame_priority.erl rename to src/h2_frame_priority.erl index 65f17dcb..8393b0f7 100644 --- a/src/http2_frame_priority.erl +++ b/src/h2_frame_priority.erl @@ -1,6 +1,6 @@ --module(http2_frame_priority). - +-module(h2_frame_priority). -include("http2.hrl"). +-behaviour(h2_frame). -export( [ @@ -20,8 +20,6 @@ -type payload() :: #priority{}. -export_type([payload/0]). --behaviour(http2_frame). - -spec format(payload()) -> iodata(). format(Payload) -> io_lib:format("[Priority: ~p]", [Payload]). diff --git a/src/http2_frame_push_promise.erl b/src/h2_frame_push_promise.erl similarity index 94% rename from src/http2_frame_push_promise.erl rename to src/h2_frame_push_promise.erl index 71ed2cfe..ececcbb9 100644 --- a/src/http2_frame_push_promise.erl +++ b/src/h2_frame_push_promise.erl @@ -1,8 +1,6 @@ --module(http2_frame_push_promise). - +-module(h2_frame_push_promise). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ @@ -51,7 +49,7 @@ read_binary(_, {error, 0, ?PROTOCOL_ERROR, <<>>}; read_binary(Bin, H=#frame_header{length=L}) -> <> = Bin, - Data = http2_padding:read_possibly_padded_payload(PayloadBin, H), + Data = h2_padding:read_possibly_padded_payload(PayloadBin, H), <<_R:1,Stream:31,BlockFragment/bits>> = Data, Payload = #push_promise{ promised_stream_id=Stream, diff --git a/src/http2_frame_rst_stream.erl b/src/h2_frame_rst_stream.erl similarity index 95% rename from src/http2_frame_rst_stream.erl rename to src/h2_frame_rst_stream.erl index c0374d32..47bbd739 100644 --- a/src/http2_frame_rst_stream.erl +++ b/src/h2_frame_rst_stream.erl @@ -1,5 +1,7 @@ --module(http2_frame_rst_stream). +-module(h2_frame_rst_stream). -include("http2.hrl"). +-behaviour(h2_frame). + -export([ new/1, error_code/1, @@ -14,8 +16,6 @@ -type payload() :: #rst_stream{}. -export_type([payload/0]). --behaviour(http2_frame). - -spec new(error_code()) -> payload(). new(ErrorCode) -> #rst_stream{ diff --git a/src/http2_frame_settings.erl b/src/h2_frame_settings.erl similarity index 98% rename from src/http2_frame_settings.erl rename to src/h2_frame_settings.erl index 5e134fc7..d015805c 100644 --- a/src/http2_frame_settings.erl +++ b/src/h2_frame_settings.erl @@ -1,8 +1,6 @@ --module(http2_frame_settings). - +-module(h2_frame_settings). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ @@ -121,7 +119,7 @@ overlay(S, {settings, []}) -> -spec send(payload()) -> binary(). send(Settings) -> - List = http2_settings:to_proplist(Settings), + List = h2_settings:to_proplist(Settings), Payload = make_payload(List), L = size(Payload), Header = <>, @@ -129,7 +127,7 @@ send(Settings) -> -spec send(payload(), payload()) -> binary(). send(PrevSettings, NewSettings) -> - Diff = http2_settings:diff(PrevSettings, NewSettings), + Diff = h2_settings:diff(PrevSettings, NewSettings), Payload = make_payload(Diff), L = size(Payload), Header = <>, diff --git a/src/http2_frame_window_update.erl b/src/h2_frame_window_update.erl similarity index 97% rename from src/http2_frame_window_update.erl rename to src/h2_frame_window_update.erl index 14e8253a..1df2fb7b 100644 --- a/src/http2_frame_window_update.erl +++ b/src/h2_frame_window_update.erl @@ -1,8 +1,6 @@ --module(http2_frame_window_update). - +-module(h2_frame_window_update). -include("http2.hrl"). - --behaviour(http2_frame). +-behaviour(h2_frame). -export( [ diff --git a/src/http2_padding.erl b/src/h2_padding.erl similarity index 98% rename from src/http2_padding.erl rename to src/h2_padding.erl index 63ae83c8..f6d109aa 100644 --- a/src/http2_padding.erl +++ b/src/h2_padding.erl @@ -1,5 +1,4 @@ --module(http2_padding). - +-module(h2_padding). -include("http2.hrl"). -export([ diff --git a/src/http2_settings.erl b/src/h2_settings.erl similarity index 98% rename from src/http2_settings.erl rename to src/h2_settings.erl index 0f22ac51..7eaf067b 100644 --- a/src/http2_settings.erl +++ b/src/h2_settings.erl @@ -1,5 +1,4 @@ --module(http2_settings). - +-module(h2_settings). -include("http2.hrl"). -export([ diff --git a/src/http2_stream.erl b/src/h2_stream.erl similarity index 95% rename from src/http2_stream.erl rename to src/h2_stream.erl index 0b8508fc..c3a3d401 100644 --- a/src/http2_stream.erl +++ b/src/h2_stream.erl @@ -1,5 +1,4 @@ --module(http2_stream). - +-module(h2_stream). -include("http2.hrl"). %% Public API @@ -288,7 +287,7 @@ open({recv_data, callback_state=CallbackState }=Stream) when ?NOT_FLAG(Flags, ?FLAG_END_STREAM) -> - Bin = http2_frame_data:data(Payload), + Bin = h2_frame_data:data(Payload), {ok, NewCBState} = CB:on_receive_request_data(Bin, CallbackState), {next_state, open, @@ -311,7 +310,7 @@ open({recv_data, callback_state=CallbackState }=Stream) when ?IS_FLAG(Flags, ?FLAG_END_STREAM) -> - Bin = http2_frame_data:data(Payload), + Bin = h2_frame_data:data(Payload), {ok, CallbackState1} = CB:on_receive_request_data(Bin, CallbackState), NewStream = Stream#stream_state{ incoming_frames=queue:in(F, IFQ), @@ -354,7 +353,7 @@ open({send_frame, #stream_state{ socket=Socket }=Stream) -> - sock:send(Socket, http2_frame:to_binary(F)), + sock:send(Socket, h2_frame:to_binary(F)), NextState = case ?IS_FLAG(Flags, ?FLAG_END_STREAM) of @@ -387,7 +386,7 @@ half_closed_remote( #stream_state{ socket=Socket }=Stream) -> - case sock:send(Socket, http2_frame:to_binary(F)) of + case sock:send(Socket, h2_frame:to_binary(F)) of ok -> case ?IS_FLAG(Flags, ?FLAG_END_STREAM) of true -> @@ -410,8 +409,7 @@ half_closed_remote(_, %% hope! half_closed_local( {recv_h, Headers}, - #stream_state{ - }=Stream) -> + #stream_state{}=Stream) -> case is_valid_headers(response, Headers) of ok -> {next_state, @@ -435,8 +433,8 @@ half_closed_local( case ?IS_FLAG(Flags, ?FLAG_END_STREAM) of true -> Data = - [ http2_frame_data:data(Payload) - || {#frame_header{type=?DATA}, Payload} <- queue:to_list(NewQ)], + [h2_frame_data:data(Payload) + || {#frame_header{type=?DATA}, Payload} <- queue:to_list(NewQ)], {next_state, closed, Stream#stream_state{ incoming_frames=queue:new(), @@ -486,16 +484,15 @@ handle_event({send_window_update, Size}, socket=Socket, stream_id=StreamId }=Stream) -> - http2_frame_window_update:send(Socket, Size, StreamId), + h2_frame_window_update:send(Socket, Size, StreamId), {next_state, StateName, - Stream#stream_state{ - }}; + Stream#stream_state{}}; handle_event({send_connection_window_update, Size}, StateName, #stream_state{ connection=ConnPid }=State) -> - http2_connection:send_window_update(ConnPid, Size), + h2_connection:send_window_update(ConnPid, Size), {next_state, StateName, State}; handle_event(_E, StateName, State) -> {next_state, StateName, State}. @@ -531,13 +528,14 @@ rst_stream_(ErrorCode, socket=Socket, stream_id=StreamId }=Stream - ) -> - RstStream = http2_frame_rst_stream:new(ErrorCode), - RstStreamBin = http2_frame:to_binary( - {#frame_header{ - stream_id=StreamId - }, - RstStream}), + ) + -> + RstStream = h2_frame_rst_stream:new(ErrorCode), + RstStreamBin = h2_frame:to_binary( + {#frame_header{ + stream_id=StreamId + }, + RstStream}), sock:send(Socket, RstStreamBin), {next_state, closed, diff --git a/src/h2_stream_set.erl b/src/h2_stream_set.erl index ed3f6ff2..ff0ec6a6 100644 --- a/src/h2_stream_set.erl +++ b/src/h2_stream_set.erl @@ -223,12 +223,12 @@ new_stream( true -> {error, ?REFUSED_STREAM, #closed_stream{id=StreamId}}; false -> - {ok, Pid} = http2_stream:start_link( - StreamId, - self(), - CBMod, - Socket - ), + {ok, Pid} = h2_stream:start_link( + StreamId, + self(), + CBMod, + Socket + ), NewStream = #active_stream{ id = StreamId, pid = Pid, @@ -248,7 +248,7 @@ new_stream( %% If this did happen, we need to kill this %% process, or it will just hang out there. - http2_stream:stop(Pid), + h2_stream:stop(Pid), {error, ?REFUSED_STREAM, #closed_stream{id=StreamId}}; NewStreamSet -> NewStreamSet @@ -715,7 +715,7 @@ s_send_what_we_can(SWS, MFS, #active_stream{}=Stream) -> type=?DATA, length=QueueSize }, - http2_frame_data:new(Stream#active_stream.queued_data)}, %% Full Body + h2_frame_data:new(Stream#active_stream.queued_data)}, %% Full Body QueueSize, Stream#active_stream{ queued_data=done, @@ -727,14 +727,14 @@ s_send_what_we_can(SWS, MFS, #active_stream{}=Stream) -> type=?DATA, length=MaxToSend }, - http2_frame_data:new(BinToSend)}, + h2_frame_data:new(BinToSend)}, MaxToSend, Stream#active_stream{ queued_data=Rest, send_window_size=SSWS-MaxToSend}} end, - _Sent = http2_stream:send_frame(Stream#active_stream.pid, Frame), + _Sent = h2_stream:send_frame(Stream#active_stream.pid, Frame), case ExitStrategy of max_frame_size -> diff --git a/test/client_server_SUITE.erl b/test/client_server_SUITE.erl index ff79c007..c1d72132 100644 --- a/test/client_server_SUITE.erl +++ b/test/client_server_SUITE.erl @@ -56,7 +56,7 @@ end_per_suite(_Config) -> complex_request(_Config) -> application:set_env(chatterbox, client_initial_window_size, 99999999), - {ok, Client} = http2_client:start_link(), + {ok, Client} = h2_client:start_link(), RequestHeaders = [ {<<":method">>, <<"GET">>}, @@ -67,7 +67,7 @@ complex_request(_Config) -> {<<"accept-encoding">>, <<"gzip, deflate">>}, {<<"user-agent">>, <<"chattercli/0.0.1 :D">>} ], - {ok, {ResponseHeaders, ResponseBody}} = http2_client:sync_request(Client, RequestHeaders, <<>>), + {ok, {ResponseHeaders, ResponseBody}} = h2_client:sync_request(Client, RequestHeaders, <<>>), ct:pal("Response Headers: ~p", [ResponseHeaders]), ct:pal("Response Body: ~p", [ResponseBody]), @@ -75,7 +75,7 @@ complex_request(_Config) -> ok. upgrade_tcp_connection(_Config) -> - {ok, Client} = http2_client:start_ssl_upgrade_link("localhost", 8081, <<>>, []), + {ok, Client} = h2_client:start_ssl_upgrade_link("localhost", 8081, <<>>, []), RequestHeaders = [ @@ -87,14 +87,14 @@ upgrade_tcp_connection(_Config) -> {<<"accept-encoding">>, <<"gzip, deflate">>}, {<<"user-agent">>, <<"chattercli/0.0.1 :D">>} ], - {ok, {ResponseHeaders, ResponseBody}} = http2_client:sync_request(Client, RequestHeaders, <<>>), + {ok, {ResponseHeaders, ResponseBody}} = h2_client:sync_request(Client, RequestHeaders, <<>>), ct:pal("Response Headers: ~p", [ResponseHeaders]), ct:pal("Response Body: ~p", [ResponseBody]), ok. basic_push(_Config) -> - {ok, Client} = http2_client:start_link(), + {ok, Client} = h2_client:start_link(), RequestHeaders = [ {<<":method">>, <<"GET">>}, @@ -105,7 +105,7 @@ basic_push(_Config) -> {<<"accept-encoding">>, <<"gzip, deflate">>}, {<<"user-agent">>, <<"chattercli/0.0.1 :D">>} ], - {ok, {ResponseHeaders, ResponseBody}} = http2_client:sync_request(Client, RequestHeaders, <<>>), + {ok, {ResponseHeaders, ResponseBody}} = h2_client:sync_request(Client, RequestHeaders, <<>>), ct:pal("Response Headers: ~p", [ResponseHeaders]), ct:pal("Response Body: ~p", [ResponseBody]), @@ -114,19 +114,19 @@ basic_push(_Config) -> %% We'll know we're done when we're notified of all the streams ending. wait_for_n_notifications(12), - Streams = http2_connection:get_streams(Client), + Streams = h2_connection:get_streams(Client), ct:pal("Streams ~p", [Streams]), - ?assertEqual(0, h2_stream_set:my_active_count(Streams)), - ?assertEqual(0, h2_stream_set:their_active_count(Streams)), + ?assertEqual(0, (h2_stream_set:my_active_count(Streams))), + ?assertEqual(0, (h2_stream_set:their_active_count(Streams))), MyActiveStreams = h2_stream_set:my_active_streams(Streams), - ?assertEqual(1, length(MyActiveStreams)), - ?assertEqual(1, h2_stream_set:stream_id(hd(MyActiveStreams))), + ?assertEqual(1, (length(MyActiveStreams))), + ?assertEqual(1, (h2_stream_set:stream_id(hd(MyActiveStreams)))), TheirActiveStreams = h2_stream_set:their_active_streams(Streams), - ?assertEqual(12, length(TheirActiveStreams)), + ?assertEqual(12, (length(TheirActiveStreams))), - [ ?assertEqual(closed, h2_stream_set:type(S)) || S <- TheirActiveStreams], + [?assertEqual(closed, (h2_stream_set:type(S))) || S <- TheirActiveStreams], ok. wait_for_n_notifications(0) -> @@ -143,7 +143,7 @@ wait_for_n_notifications(N) -> end. get_peer_in_handler(_Config) -> - {ok, Client} = http2_client:start_link(), + {ok, Client} = h2_client:start_link(), RequestHeaders = [ {<<":method">>, <<"GET">>}, @@ -156,13 +156,13 @@ get_peer_in_handler(_Config) -> ], - {ok, {ResponseHeaders, ResponseBody}} = http2_client:sync_request(Client, RequestHeaders, <<>>), + {ok, {ResponseHeaders, ResponseBody}} = h2_client:sync_request(Client, RequestHeaders, <<>>), ct:pal("Response Headers: ~p", [ResponseHeaders]), ct:pal("Response Body: ~p", [ResponseBody]), ok. send_body_opts(_Config) -> - {ok, Client} = http2_client:start_link(), + {ok, Client} = h2_client:start_link(), RequestHeaders = [ {<<":method">>, <<"GET">>}, @@ -176,10 +176,10 @@ send_body_opts(_Config) -> ExpectedResponseBody = <<"BodyPart1\nBodyPart2">>, - {ok, {ResponseHeaders, ResponseBody}} = http2_client:sync_request(Client, RequestHeaders, <<>>), + {ok, {ResponseHeaders, ResponseBody}} = h2_client:sync_request(Client, RequestHeaders, <<>>), ct:pal("Response Headers: ~p", [ResponseHeaders]), ct:pal("Response Body: ~p", [ResponseBody]), - ?assertEqual(ExpectedResponseBody, iolist_to_binary(ResponseBody)), + ?assertEqual(ExpectedResponseBody, (iolist_to_binary(ResponseBody))), ok. echo_body(_Config) -> @@ -203,13 +203,13 @@ echo_body(_Config) -> flags=?FLAG_END_HEADERS, stream_id=3 }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HeaderFrame]), Body = crypto:rand_bytes(128), - BodyFrames = http2_frame_data:to_frames(3, Body, #settings{max_frame_size=64}), + BodyFrames = h2_frame_data:to_frames(3, Body, #settings{max_frame_size=64}), http2c:send_unaltered_frames(Client, BodyFrames), timer:sleep(300), @@ -217,8 +217,8 @@ echo_body(_Config) -> DataFrames = lists:filter(fun({#frame_header{type=?DATA}, _}) -> true; (_) -> false end, Frames), ResponseData = lists:map(fun({_, DataP}) -> - http2_frame_data:data(DataP) + h2_frame_data:data(DataP) end, DataFrames), io:format("Body: ~p, response: ~p~n", [Body, ResponseData]), - ?assertEqual(Body, iolist_to_binary(ResponseData)), + ?assertEqual(Body, (iolist_to_binary(ResponseData))), ok. diff --git a/test/double_body_handler.erl b/test/double_body_handler.erl index 14a1f11a..ef3a6c3f 100644 --- a/test/double_body_handler.erl +++ b/test/double_body_handler.erl @@ -2,7 +2,7 @@ -include_lib("chatterbox/include/http2.hrl"). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -43,9 +43,8 @@ on_request_end_stream(State=#state{conn_pid=ConnPid, ResponseHeaders = [ {<<":status">>,<<"200">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, <<"BodyPart1\n">>, - [{send_end_stream, false}]), - http2_connection:send_body(ConnPid, StreamId, <<"BodyPart2">>), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, <<"BodyPart1\n">>, + [{send_end_stream, false}]), + h2_connection:send_body(ConnPid, StreamId, <<"BodyPart2">>), {ok, State}. - diff --git a/test/echo_handler.erl b/test/echo_handler.erl index b089443e..64c68371 100644 --- a/test/echo_handler.erl +++ b/test/echo_handler.erl @@ -2,7 +2,7 @@ -include_lib("chatterbox/include/http2.hrl"). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -46,7 +46,6 @@ on_request_end_stream(State=#state{conn_pid=ConnPid, ResponseHeaders = [ {<<":status">>,<<"200">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, Buffer), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, Buffer), {ok, State}. - diff --git a/test/flow_control_SUITE.erl b/test/flow_control_SUITE.erl index e5e86dbf..5daca953 100644 --- a/test/flow_control_SUITE.erl +++ b/test/flow_control_SUITE.erl @@ -60,10 +60,10 @@ exceed_server_connection_receive_window(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1 , length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. exceed_server_stream_receive_window(_Config) -> @@ -75,16 +75,16 @@ exceed_server_stream_receive_window(_Config) -> %% now challenge that {WUH, _} = WindowUpdate, - ?assertEqual(?WINDOW_UPDATE, WUH#frame_header.type), + ?assertEqual(?WINDOW_UPDATE, (WUH#frame_header.type)), %% Check for RST_STREAM Resp = http2c:wait_for_n_frames(Client, 3, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. server_buffer_response(_Config) -> @@ -100,7 +100,7 @@ server_buffer_response(_Config) -> type=?HEADERS, flags=?FLAG_END_HEADERS bor ?FLAG_END_STREAM, stream_id=3}, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF]), @@ -126,7 +126,7 @@ data_frame_size(Frames) -> DataFrames = lists:filter(fun({#frame_header{type=?DATA}, _}) -> true; (_) -> false end, Frames), lists:foldl(fun({_FH, DataP}, Acc) -> - Data = http2_frame_data:data(DataP), + Data = h2_frame_data:data(DataP), Acc + byte_size(Data) end, 0, DataFrames). @@ -135,7 +135,7 @@ send_window_update(Client, Size) -> [{#frame_header{length=4, type=?WINDOW_UPDATE, stream_id=3}, - http2_frame_window_update:new(Size) + h2_frame_window_update:new(Size) } ]). send_n_bytes(N) -> @@ -162,7 +162,7 @@ send_n_bytes(N) -> flags=?FLAG_END_HEADERS, stream_id=3 }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HeaderFrame]), @@ -172,7 +172,7 @@ send_n_bytes(N) -> %% So now, send N bytes and we should get some desired error. Data = crypto:rand_bytes(N), - Frames = http2_frame_data:to_frames(3, Data, #settings{}), + Frames = h2_frame_data:to_frames(3, Data, #settings{}), http2c:send_unaltered_frames(Client, Frames), diff --git a/test/flow_control_handler.erl b/test/flow_control_handler.erl index e7e83146..477cdf44 100644 --- a/test/flow_control_handler.erl +++ b/test/flow_control_handler.erl @@ -4,7 +4,7 @@ -define(SEND_BYTES, 68). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -46,10 +46,9 @@ on_request_end_stream(State=#state{conn_pid=ConnPid, ResponseHeaders = [ {<<":status">>,<<"200">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, crypto:rand_bytes(?SEND_BYTES), - [{send_end_stream, false}]), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, crypto:rand_bytes(?SEND_BYTES), + [{send_end_stream, false}]), timer:sleep(200), - http2_connection:send_body(ConnPid, StreamId, crypto:rand_bytes(?SEND_BYTES)), + h2_connection:send_body(ConnPid, StreamId, crypto:rand_bytes(?SEND_BYTES)), {ok, State}. - diff --git a/test/header_continuation_SUITE.erl b/test/header_continuation_SUITE.erl index 33d3c5da..743ddc73 100644 --- a/test/header_continuation_SUITE.erl +++ b/test/header_continuation_SUITE.erl @@ -40,16 +40,16 @@ basic_continuation(_Config) -> Frames = [ {#frame_header{length=8,type=?HEADERS,flags=?FLAG_END_STREAM,stream_id=3}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,stream_id=3}, - http2_frame_continuation:new(H2)}, + h2_frame_continuation:new(H2)}, {#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3}, - http2_frame_continuation:new(H3)} + h2_frame_continuation:new(H3)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 3, 2), cthr:pal("Resp: ~p", [Resp]), - ?assertEqual(2, length(Resp)), + ?assertEqual(2, (length(Resp))), ok. @@ -73,17 +73,17 @@ basic_continuation_end_stream_first(_Config) -> Frames = [ {#frame_header{length=8,type=?HEADERS,flags=?FLAG_END_STREAM,stream_id=3}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,stream_id=3}, - http2_frame_continuation:new(H2)}, + h2_frame_continuation:new(H2)}, {#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3}, - http2_frame_continuation:new(H3)} + h2_frame_continuation:new(H3)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 3, 2), cthr:pal("Resp: ~p", [Resp]), - ?assertEqual(2, length(Resp)), + ?assertEqual(2, (length(Resp))), ok. bad_frame_wrong_type_between_continuations(_Config) -> @@ -107,24 +107,24 @@ bad_frame_wrong_type_between_continuations(_Config) -> Frames = [ {#frame_header{length=8,type=?HEADERS,stream_id=3}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,stream_id=3}, - http2_frame_continuation:new(H2)}, + h2_frame_continuation:new(H2)}, {#frame_header{length=8,type=?HEADERS,stream_id=3}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3}, - http2_frame_continuation:new(H3)} + h2_frame_continuation:new(H3)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 3, 0), cthr:pal("Resp: ~p", [Resp]), - ?assertEqual(0, length(Resp)), + ?assertEqual(0, (length(Resp))), Resp2 = http2c:wait_for_n_frames(Client, 0, 1), 1 = length(Resp2), [{GoAwayH, GoAway}] = Resp2, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. bad_frame_wrong_stream_between_continuations(_Config) -> @@ -148,24 +148,24 @@ bad_frame_wrong_stream_between_continuations(_Config) -> Frames = [ {#frame_header{length=8,type=?HEADERS,stream_id=3}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,stream_id=3}, - http2_frame_continuation:new(H2)}, + h2_frame_continuation:new(H2)}, {#frame_header{length=8,type=?HEADERS,stream_id=5}, - http2_frame_headers:new(H1)}, + h2_frame_headers:new(H1)}, {#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3}, - http2_frame_continuation:new(H3)} + h2_frame_continuation:new(H3)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 3, 0), cthr:pal("Resp: ~p", [Resp]), - ?assertEqual(0, length(Resp)), + ?assertEqual(0, (length(Resp))), Resp2 = http2c:wait_for_n_frames(Client, 0, 1), 1 = length(Resp2), [{GoAwayH, GoAway}] = Resp2, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_frame_size_SUITE.erl b/test/http2_frame_size_SUITE.erl index ea3bbefc..ca8fa317 100644 --- a/test/http2_frame_size_SUITE.erl +++ b/test/http2_frame_size_SUITE.erl @@ -39,10 +39,10 @@ send_wrong_size(Type, _Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FRAME_SIZE_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FRAME_SIZE_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. frame_too_big(_Config) -> @@ -54,16 +54,16 @@ frame_too_big(_Config) -> type=?HEADERS, flags=?FLAG_END_HEADERS, stream_id=3}, - http2_frame_headers:new(<<1:131136>>)} + h2_frame_headers:new(<<1:131136>>)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FRAME_SIZE_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FRAME_SIZE_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. euc(_Config) -> @@ -93,14 +93,14 @@ euc(_Config) -> Frames = [ {#frame_header{length=byte_size(HeadersBin1),type=?HEADERS,flags=?FLAG_END_HEADERS,stream_id=3}, - http2_frame_headers:new(HeadersBin1)}, + h2_frame_headers:new(HeadersBin1)}, {#frame_header{length=byte_size(HeadersBin2),type=?HEADERS,flags=?FLAG_END_HEADERS,stream_id=5}, - http2_frame_headers:new(HeadersBin2)}, + h2_frame_headers:new(HeadersBin2)}, {#frame_header{length=byte_size(HeadersBin3),type=?HEADERS,flags=?FLAG_END_HEADERS,stream_id=7}, - http2_frame_headers:new(HeadersBin3)} + h2_frame_headers:new(HeadersBin3)} ], http2c:send_unaltered_frames(Client, Frames), Resp = http2c:wait_for_n_frames(Client, 0, 0), - ?assertEqual(0, length(Resp)). + ?assertEqual(0, (length(Resp))). diff --git a/test/http2_spec_4_3_SUITE.erl b/test/http2_spec_4_3_SUITE.erl index b3ef7675..3e816fa9 100644 --- a/test/http2_spec_4_3_SUITE.erl +++ b/test/http2_spec_4_3_SUITE.erl @@ -29,8 +29,8 @@ sends_invalid_header_block_fragment(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?COMPRESSION_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?COMPRESSION_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_5_1_SUITE.erl b/test/http2_spec_5_1_SUITE.erl index 26f65dc2..f69e3f10 100644 --- a/test/http2_spec_5_1_SUITE.erl +++ b/test/http2_spec_5_1_SUITE.erl @@ -65,12 +65,12 @@ total_streams_above_max_concurrent(Config) -> lists:foldl( fun(StreamId, EncodeContext) -> {H1, NewEC} = - http2_frame_headers:to_frames( - StreamId, - RequestHeaders, - EncodeContext, - 16384, - true), + h2_frame_headers:to_frames( + StreamId, + RequestHeaders, + EncodeContext, + 16384, + true), http2c:send_unaltered_frames(Client, H1), NewEC end, @@ -86,32 +86,32 @@ total_streams_above_max_concurrent(Config) -> ?assertEqual([], Resp0), [ begin [{FH1,_FB1},{FH2,_FB2}] = http2c:get_frames(Client, StreamId), - ?assertEqual(StreamId, FH1#frame_header.stream_id), - ?assertEqual(?HEADERS, FH1#frame_header.type), - ?assertEqual(StreamId, FH2#frame_header.stream_id), - ?assertEqual(?DATA, FH2#frame_header.type) - end || StreamId <- StreamIds], + ?assertEqual(StreamId, (FH1#frame_header.stream_id)), + ?assertEqual(?HEADERS, (FH1#frame_header.type)), + ?assertEqual(StreamId, (FH2#frame_header.stream_id)), + ?assertEqual(?DATA, (FH2#frame_header.type)) + end || StreamId <- StreamIds], %% Now, open AStreamTooFar {HFinal, _UnusedEC} = - http2_frame_headers:to_frames( - AStreamTooFar, - RequestHeaders, - FinalEC, - 16384, - true), + h2_frame_headers:to_frames( + AStreamTooFar, + RequestHeaders, + FinalEC, + 16384, + true), http2c:send_unaltered_frames(Client, HFinal), %% Response should be a real response, because we haven't exceeded %% anything Response = http2c:wait_for_n_frames(Client, AStreamTooFar, 2), - ?assertEqual(2, length(Response)), + ?assertEqual(2, (length(Response))), [{RH1,_RB1},{RH2,_RB2}] = Response, - ?assertEqual(AStreamTooFar, RH1#frame_header.stream_id), - ?assertEqual(?HEADERS, RH1#frame_header.type), - ?assertEqual(AStreamTooFar, RH2#frame_header.stream_id), - ?assertEqual(?DATA, RH2#frame_header.type), + ?assertEqual(AStreamTooFar, (RH1#frame_header.stream_id)), + ?assertEqual(?HEADERS, (RH1#frame_header.type)), + ?assertEqual(AStreamTooFar, (RH2#frame_header.stream_id)), + ?assertEqual(?DATA, (RH2#frame_header.type)), ok. exceeds_max_concurrent_streams(Config) -> @@ -137,12 +137,12 @@ exceeds_max_concurrent_streams(Config) -> lists:foldl( fun(StreamId, EncodeContext) -> {H1, NewEC} = - http2_frame_headers:to_frames( - StreamId, - RequestHeaders, - EncodeContext, - 16384, - false), + h2_frame_headers:to_frames( + StreamId, + RequestHeaders, + EncodeContext, + 16384, + false), http2c:send_unaltered_frames(Client, H1), NewEC end, @@ -163,39 +163,39 @@ exceeds_max_concurrent_streams(Config) -> %% Now, open AStreamTooFar {HFinal, _UnusedEC} = - http2_frame_headers:to_frames( - AStreamTooFar, - RequestHeaders, - FinalEC, - 16384, - false), + h2_frame_headers:to_frames( + AStreamTooFar, + RequestHeaders, + FinalEC, + 16384, + false), http2c:send_unaltered_frames(Client, HFinal), %% Response should be RST_STREAM ?REFUSED_STREAM Response = http2c:wait_for_n_frames(Client, AStreamTooFar, 1), - ?assertEqual(1, length(Response)), + ?assertEqual(1, (length(Response))), [{RstH, RstP}] = Response, - ?assertEqual(?RST_STREAM, RstH#frame_header.type), - ?assertEqual(?REFUSED_STREAM, http2_frame_rst_stream:error_code(RstP)), + ?assertEqual(?RST_STREAM, (RstH#frame_header.type)), + ?assertEqual(?REFUSED_STREAM, (h2_frame_rst_stream:error_code(RstP))), ok. sends_rst_stream_to_idle(_Config) -> {ok, Client} = http2c:start_link(), - RstStream = http2_frame_rst_stream:new(?CANCEL), - RstStreamBin = http2_frame:to_binary( - {#frame_header{ - stream_id=1 - }, - RstStream}), + RstStream = h2_frame_rst_stream:new(?CANCEL), + RstStreamBin = h2_frame:to_binary( + {#frame_header{ + stream_id=1 + }, + RstStream}), http2c:send_binary(Client, RstStreamBin), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{_GoAwayH, GoAway}] = Resp, - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. half_closed_remote_sends_headers(_Config) -> @@ -212,53 +212,53 @@ half_closed_remote_sends_headers(_Config) -> ], {H1, EC} = - http2_frame_headers:to_frames(1, - RequestHeaders, - hpack:new_context(), - 16384, - true), + h2_frame_headers:to_frames(1, + RequestHeaders, + hpack:new_context(), + 16384, + true), http2c:send_unaltered_frames(Client, H1), %% The stream should be half closed remote now {H2, _EC2} = - http2_frame_headers:to_frames(1, - RequestHeaders, - EC, - 16384, - true), + h2_frame_headers:to_frames(1, + RequestHeaders, + EC, + 16384, + true), http2c:send_unaltered_frames(Client, H2), Resp = http2c:wait_for_n_frames(Client, 1, 3), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(true, length(Resp) >= 3), + ?assertEqual(true, (length(Resp) >= 3)), [ {HeadersH, _}, {DataH, _}, {RstStreamH, RstStream}|_] = Resp, - ?assertEqual(?HEADERS, HeadersH#frame_header.type), - ?assertEqual(?DATA, DataH#frame_header.type), - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?STREAM_CLOSED, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?HEADERS, (HeadersH#frame_header.type)), + ?assertEqual(?DATA, (DataH#frame_header.type)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?STREAM_CLOSED, (h2_frame_rst_stream:error_code(RstStream))), ok. sends_window_update_to_idle(_Config) -> {ok, Client} = http2c:start_link(), - WUBin = http2_frame:to_binary( - {#frame_header{ - stream_id=1 - }, - http2_frame_window_update:new(1) - }), + WUBin = h2_frame:to_binary( + {#frame_header{ + stream_id=1 + }, + h2_frame_window_update:new(1) + }), http2c:send_binary(Client, WUBin), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. client_sends_even_stream_id(_Config) -> @@ -276,18 +276,18 @@ client_sends_even_stream_id(_Config) -> ], {H, _} = - http2_frame_headers:to_frames(2, - RequestHeaders, - hpack:new_context(), - 16384, - false), + h2_frame_headers:to_frames(2, + RequestHeaders, + hpack:new_context(), + 16384, + false), http2c:send_unaltered_frames(Client, H), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_5_3_SUITE.erl b/test/http2_spec_5_3_SUITE.erl index 880d1218..ba4f9b71 100644 --- a/test/http2_spec_5_3_SUITE.erl +++ b/test/http2_spec_5_3_SUITE.erl @@ -43,10 +43,10 @@ sends_header_frame_that_depends_on_itself(_Config) -> flags=?FLAG_END_HEADERS bor ?FLAG_PRIORITY, type=?HEADERS }, - http2_frame_headers:new( - http2_frame_priority:new(0,1,1), - HeadersBin - ) + h2_frame_headers:new( + h2_frame_priority:new(0,1,1), + HeadersBin + ) }, @@ -54,10 +54,10 @@ sends_header_frame_that_depends_on_itself(_Config) -> Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. sends_priority_frame_that_depends_on_itself(_Config) -> @@ -69,17 +69,17 @@ sends_priority_frame_that_depends_on_itself(_Config) -> type=?PRIORITY, length=5 }, - http2_frame_priority:new(0,1,0) + h2_frame_priority:new(0,1,0) }, http2c:send_unaltered_frames(Client, [PriorityFrame]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. sends_priority_frame_that_depends_on_itself_later(_Config) -> @@ -104,7 +104,7 @@ sends_priority_frame_that_depends_on_itself_later(_Config) -> flags=?FLAG_END_HEADERS,% bor ?FLAG_END_STREAM, type=?HEADERS }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, PriorityFrame = @@ -113,15 +113,15 @@ sends_priority_frame_that_depends_on_itself_later(_Config) -> type=?PRIORITY, length=5 }, - http2_frame_priority:new(0,1,0) + h2_frame_priority:new(0,1,0) }, http2c:send_unaltered_frames(Client, [F, PriorityFrame]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. diff --git a/test/http2_spec_5_5_SUITE.erl b/test/http2_spec_5_5_SUITE.erl index 1a907e1d..d30e6760 100644 --- a/test/http2_spec_5_5_SUITE.erl +++ b/test/http2_spec_5_5_SUITE.erl @@ -37,13 +37,13 @@ sends_unknown_extension_frame(_Config) -> stream_id=0, length=8 }, - http2_frame_ping:new(Data) + h2_frame_ping:new(Data) } ]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{PingH, _PingBody}] = Resp, - ?assertEqual(?PING, PingH#frame_header.type), + ?assertEqual(?PING, (PingH#frame_header.type)), ok. diff --git a/test/http2_spec_6_1_SUITE.erl b/test/http2_spec_6_1_SUITE.erl index ea569d66..01eb9200 100644 --- a/test/http2_spec_6_1_SUITE.erl +++ b/test/http2_spec_6_1_SUITE.erl @@ -40,7 +40,7 @@ sends_data_with_invalid_pad_length(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS bor ?FLAG_PADDED }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF]), @@ -51,8 +51,8 @@ sends_data_with_invalid_pad_length(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_6_2_SUITE.erl b/test/http2_spec_6_2_SUITE.erl index 2bd9e1c8..07c49622 100644 --- a/test/http2_spec_6_2_SUITE.erl +++ b/test/http2_spec_6_2_SUITE.erl @@ -43,16 +43,16 @@ sends_header_with_invalid_pad_length(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS bor ?FLAG_PADDED }, - http2_frame_headers:new(PaddedBin) + h2_frame_headers:new(PaddedBin) }, http2c:send_unaltered_frames(Client, [F]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. sends_go_example(_Config) -> @@ -81,8 +81,8 @@ sends_go_example(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_6_4_SUITE.erl b/test/http2_spec_6_4_SUITE.erl index 18acd2b0..a35c77ac 100644 --- a/test/http2_spec_6_4_SUITE.erl +++ b/test/http2_spec_6_4_SUITE.erl @@ -25,15 +25,15 @@ sends_rst_stream_to_idle(_Config) -> #frame_header{ stream_id=1 }, - http2_frame_rst_stream:new(?CANCEL) + h2_frame_rst_stream:new(?CANCEL) }, http2c:send_unaltered_frames(Client, [F]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_6_5_SUITE.erl b/test/http2_spec_6_5_SUITE.erl index 1324c336..d2471057 100644 --- a/test/http2_spec_6_5_SUITE.erl +++ b/test/http2_spec_6_5_SUITE.erl @@ -31,10 +31,10 @@ sends_invalid_push_setting(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. sends_value_above_max_flow_control_window_size(_Config) -> @@ -45,10 +45,10 @@ sends_value_above_max_flow_control_window_size(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. sends_max_frame_size_too_small(_Config) -> @@ -59,11 +59,11 @@ sends_max_frame_size_too_small(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), - [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), - ok. + ?assertEqual(1, (length(Resp))), + [{GoAwayH, GoAway}] = Resp, + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), + ok. sends_max_frame_size_too_big(_Config) -> {ok, Client} = http2c:start_link(), @@ -73,8 +73,8 @@ sends_max_frame_size_too_big(_Config) -> Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), - [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), - ok. + ?assertEqual(1, (length(Resp))), + [{GoAwayH, GoAway}] = Resp, + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), + ok. diff --git a/test/http2_spec_6_9_SUITE.erl b/test/http2_spec_6_9_SUITE.erl index 2837812d..afa51306 100644 --- a/test/http2_spec_6_9_SUITE.erl +++ b/test/http2_spec_6_9_SUITE.erl @@ -43,20 +43,20 @@ send_window_update(_Config) -> {<<"user-agent">>, <<"chattercli/0.0.1 :D">>} ], {H, _} = - http2_frame_headers:to_frames(1, - RequestHeaders, - hpack:new_context(), - 16384, - true), + h2_frame_headers:to_frames(1, + RequestHeaders, + hpack:new_context(), + 16384, + true), http2c:send_unaltered_frames(Client, H), Resp0 = http2c:wait_for_n_frames(Client, 1, 2), ct:pal("Resp0: ~p", [Resp0]), - ?assertEqual(2, length(Resp0)), % Should get one byte: + ?assertEqual(2, (length(Resp0))), % Should get one byte: [_RespHeaders, {Frame1H, _}] = Resp0, - ?assertEqual(1, Frame1H#frame_header.length), + ?assertEqual(1, (Frame1H#frame_header.length)), http2c:send_unaltered_frames( Client, @@ -64,17 +64,17 @@ send_window_update(_Config) -> {#frame_header{ stream_id=1 }, - http2_frame_window_update:new(1) + h2_frame_window_update:new(1) } ] ), Resp1 = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp1: ~p", [Resp1]), - ?assertEqual(1, length(Resp1)), + ?assertEqual(1, (length(Resp1))), [{Frame2H, _}] = Resp1, - ?assertEqual(1, Frame2H#frame_header.length), + ?assertEqual(1, (Frame2H#frame_header.length)), ok. @@ -90,16 +90,16 @@ send_window_update_with_zero(_Config) -> length=24, stream_id=0 }, - http2_frame_window_update:new(0) + h2_frame_window_update:new(0) } ]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. send_window_update_with_zero_on_stream(_Config) -> @@ -117,11 +117,11 @@ send_window_update_with_zero_on_stream(_Config) -> ], {[H], _} = - http2_frame_headers:to_frames(1, - RequestHeaders, - hpack:new_context(), - 16384, - false), + h2_frame_headers:to_frames(1, + RequestHeaders, + hpack:new_context(), + 16384, + false), http2c:send_unaltered_frames( Client, @@ -131,16 +131,16 @@ send_window_update_with_zero_on_stream(_Config) -> length=24, stream_id=1 }, - http2_frame_window_update:new(0) + h2_frame_window_update:new(0) } ]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. send_window_updates_greater_than_max(_Config) -> @@ -151,17 +151,17 @@ send_window_updates_greater_than_max(_Config) -> length=24, stream_id=0 }, - http2_frame_window_update:new(2147483647) + h2_frame_window_update:new(2147483647) }, http2c:send_unaltered_frames(Client, [ F, F ]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. send_window_updates_greater_than_max_on_stream(_Config) -> @@ -179,18 +179,18 @@ send_window_updates_greater_than_max_on_stream(_Config) -> ], {[H], _} = - http2_frame_headers:to_frames(1, - RequestHeaders, - hpack:new_context(), - 16384, - false), + h2_frame_headers:to_frames(1, + RequestHeaders, + hpack:new_context(), + 16384, + false), WU = {#frame_header{ type=?WINDOW_UPDATE, length=24, stream_id=1 }, - http2_frame_window_update:new(2147483647) + h2_frame_window_update:new(2147483647) }, http2c:send_unaltered_frames( @@ -199,10 +199,10 @@ send_window_updates_greater_than_max_on_stream(_Config) -> Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{RstStreamH, RstStream}] = Resp, - ?assertEqual(?RST_STREAM, RstStreamH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_rst_stream:error_code(RstStream)), + ?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_rst_stream:error_code(RstStream))), ok. send_settings_initial_window_size_greater_than_max(_Config) -> @@ -212,9 +212,9 @@ send_settings_initial_window_size_greater_than_max(_Config) -> http2c:send_binary(Client, Bin), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{_GoAwayH, GoAway}] = Resp, [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?FLOW_CONTROL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?FLOW_CONTROL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/http2_spec_8_1_SUITE.erl b/test/http2_spec_8_1_SUITE.erl index 21b8175c..0ee02e8b 100644 --- a/test/http2_spec_8_1_SUITE.erl +++ b/test/http2_spec_8_1_SUITE.erl @@ -47,15 +47,15 @@ sends_head_request(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS bor ?FLAG_END_STREAM }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{Header, _Payload}] = Resp, - ?assertEqual(?HEADERS, Header#frame_header.type), + ?assertEqual(?HEADERS, (Header#frame_header.type)), ok. sends_headers_containing_trailer_part(_Config) -> @@ -80,7 +80,7 @@ sends_headers_containing_trailer_part(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, Data = { @@ -88,7 +88,7 @@ sends_headers_containing_trailer_part(_Config) -> stream_id=1, length=4 }, - http2_frame_data:new(<<"test">>) + h2_frame_data:new(<<"test">>) }, RequestTrailers = @@ -101,7 +101,7 @@ sends_headers_containing_trailer_part(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS bor ?FLAG_END_STREAM }, - http2_frame_headers:new(TrailersBin) + h2_frame_headers:new(TrailersBin) }, http2c:send_unaltered_frames(Client, [HF, Data, TF]), @@ -109,13 +109,13 @@ sends_headers_containing_trailer_part(_Config) -> Resp = http2c:wait_for_n_frames(Client, 1, 3), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(3, length(Resp)), + ?assertEqual(3, (length(Resp))), [{WUH,_}, {HeaderH, _}, {DataH, _}] = Resp, - ?assertEqual(?WINDOW_UPDATE, WUH#frame_header.type), - ?assertEqual(?HEADERS, HeaderH#frame_header.type), - ?assertEqual(?DATA, DataH#frame_header.type), + ?assertEqual(?WINDOW_UPDATE, (WUH#frame_header.type)), + ?assertEqual(?HEADERS, (HeaderH#frame_header.type)), + ?assertEqual(?DATA, (DataH#frame_header.type)), ok. sends_second_headers_with_no_end_stream(_Config) -> @@ -140,7 +140,7 @@ sends_second_headers_with_no_end_stream(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, Data = { @@ -148,7 +148,7 @@ sends_second_headers_with_no_end_stream(_Config) -> stream_id=1, length=2 }, - http2_frame_data:new(<<"hi">>) + h2_frame_data:new(<<"hi">>) }, RequestTrailers = @@ -161,18 +161,18 @@ sends_second_headers_with_no_end_stream(_Config) -> stream_id=1, flags=?FLAG_END_HEADERS }, - http2_frame_headers:new(TrailersBin) + h2_frame_headers:new(TrailersBin) }, http2c:send_unaltered_frames(Client, [HF, Data, TF]), Resp = http2c:wait_for_n_frames(Client, 1, 2), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(2, length(Resp)), + ?assertEqual(2, (length(Resp))), [{WUH, _},{Header, Payload}] = Resp, - ?assertEqual(?WINDOW_UPDATE, WUH#frame_header.type), - ?assertEqual(?RST_STREAM, Header#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(Payload)), + ?assertEqual(?WINDOW_UPDATE, (WUH#frame_header.type)), + ?assertEqual(?RST_STREAM, (Header#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(Payload))), ok. sends_uppercase_headers(_Config) -> @@ -232,16 +232,16 @@ test_rst_stream(RequestHeaders) -> stream_id=1, flags=?FLAG_END_HEADERS }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{Header, Payload}] = Resp, - ?assertEqual(?RST_STREAM, Header#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(Payload)), + ?assertEqual(?RST_STREAM, (Header#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(Payload))), ok. sends_connection_header(_Config) -> @@ -327,7 +327,7 @@ sends_invalid_content_length_single_frame(_Config) -> flags=?FLAG_END_STREAM, length=8, stream_id=1 - }, http2_frame_data:new(<<1,2,3,4,5,6,7,8>>)}]). + }, h2_frame_data:new(<<1,2,3,4,5,6,7,8>>)}]). sends_invalid_content_length_multi_frame(_Config) -> test_content_length( @@ -335,13 +335,13 @@ sends_invalid_content_length_multi_frame(_Config) -> type=?DATA, length=8, stream_id=1 - }, http2_frame_data:new(<<1,2,3,4,5,6,7,8>>)}, + }, h2_frame_data:new(<<1,2,3,4,5,6,7,8>>)}, {#frame_header{ type=?DATA, length=8, flags=?FLAG_END_STREAM, stream_id=1 - }, http2_frame_data:new(<<11,12,13,14,15,16,17,18>>)} + }, h2_frame_data:new(<<11,12,13,14,15,16,17,18>>)} ]). @@ -365,7 +365,7 @@ test_content_length(DataFrames) -> stream_id=1, flags=?FLAG_END_HEADERS }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF|DataFrames]), @@ -373,22 +373,21 @@ test_content_length(DataFrames) -> Resp = http2c:wait_for_n_frames(Client, 1, ExpectedFrameCount), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(ExpectedFrameCount, length(Resp)), + ?assertEqual(ExpectedFrameCount, (length(Resp))), [ErrorFrame|WindowUpdates] = lists:reverse(Resp), {Header, Payload} = ErrorFrame, - ?assertEqual(?RST_STREAM, Header#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(Payload)), - - ExpectedWUs = [ - {#frame_header{ - type=?WINDOW_UPDATE, - length=4, - stream_id=1 - }, - http2_frame_window_update:new(8) - } - || _ <- lists:seq(1,length(DataFrames))], + ?assertEqual(?RST_STREAM, (Header#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(Payload))), + + ExpectedWUs = [{#frame_header{ + type=?WINDOW_UPDATE, + length=4, + stream_id=1 + }, + h2_frame_window_update:new(8) + } + || _ <- lists:seq(1,length(DataFrames))], WindowUpdates = ExpectedWUs, @@ -414,14 +413,14 @@ sends_non_integer_content_length(_Context) -> stream_id=1, flags=?FLAG_END_HEADERS bor ?FLAG_END_STREAM }, - http2_frame_headers:new(HeadersBin) + h2_frame_headers:new(HeadersBin) }, http2c:send_unaltered_frames(Client, [HF]), Resp = http2c:wait_for_n_frames(Client, 1, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{Header, Payload}] = Resp, - ?assertEqual(?RST_STREAM, Header#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_rst_stream:error_code(Payload)), + ?assertEqual(?RST_STREAM, (Header#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(Payload))), ok. diff --git a/test/http2c.erl b/test/http2c.erl index 60631b68..c3fa9ed3 100644 --- a/test/http2c.erl +++ b/test/http2c.erl @@ -70,7 +70,7 @@ send_binary(Pid, Binary) -> %% ifdef(TEST) -spec send_unaltered_frames(pid(), [http2_frame:frame()]) -> ok. send_unaltered_frames(Pid, Frames) -> - [ send_binary(Pid, http2_frame:to_binary(F)) || F <- Frames], + [send_binary(Pid, h2_frame:to_binary(F)) || F <- Frames], ok. get_frames(Pid, StreamId) -> @@ -136,18 +136,18 @@ init([]) -> Transport:send(Socket, <>), %% Settings Handshake - {_SSH, ServerSettings} = http2_frame:read({Transport, Socket}, 1000), - http2_frame_settings:ack({Transport, Socket}), + {_SSH, ServerSettings} = h2_frame:read({Transport, Socket}, 1000), + h2_frame_settings:ack({Transport, Socket}), ClientSettings = chatterbox:settings(client), - lager:debug("[client] settings: ~p", [http2_settings:to_proplist(ClientSettings)]), + lager:debug("[client] settings: ~p", [h2_settings:to_proplist(ClientSettings)]), - BinToSend = http2_frame_settings:send(#settings{}, ClientSettings), + BinToSend = h2_frame_settings:send(#settings{}, ClientSettings), Transport:send(Socket, BinToSend), - {AH, PAck} = http2_frame:read({Transport, Socket}, 100), + {AH, PAck} = h2_frame:read({Transport, Socket}, 100), lager:debug("AH: ~p, ~p", [AH, PAck]), - Ack = ?IS_FLAG(AH#frame_header.flags, ?FLAG_ACK), + Ack = ?IS_FLAG((AH#frame_header.flags), ?FLAG_ACK), lager:debug("Ack: ~p", [Ack]), case Transport of @@ -158,7 +158,7 @@ init([]) -> end, {ok, #http2c_state{ socket = {Transport, Socket}, - send_settings = http2_frame_settings:overlay(#settings{}, ServerSettings) + send_settings = h2_frame_settings:overlay(#settings{}, ServerSettings) }}. %% Handling call messages @@ -195,10 +195,10 @@ handle_cast(recv, #http2c_state{ incoming_frames = Frames }=State) -> RawHeader = Transport:recv(Socket, 9), - {FHeader, <<>>} = http2_frame:read_binary_frame_header(RawHeader), + {FHeader, <<>>} = h2_frame:read_binary_frame_header(RawHeader), lager:info("http2c recv ~p", [FHeader]), RawBody = Transport:recv(Socket, FHeader#frame_header.length), - {ok, Payload, <<>>} = http2_frame:read_binary_payload(RawBody, FHeader), + {ok, Payload, <<>>} = h2_frame:read_binary_payload(RawBody, FHeader), F = {FHeader, Payload}, gen_server:cast(self(), recv), {noreply, State#http2c_state{incoming_frames = Frames ++ [F]}}; @@ -257,11 +257,11 @@ code_change(_OldVsn, State, _Extra) -> process_binary(<<>>, undefined, <<>>, Frames) -> {Frames, undefined, <<>>}; process_binary(<>, undefined, <<>>, Frames) -> - {Header, <<>>} = http2_frame:read_binary_frame_header(HeaderBin), + {Header, <<>>} = h2_frame:read_binary_frame_header(HeaderBin), L = Header#frame_header.length, case byte_size(Bin) >= L of true -> - {ok, Payload, Rem} = http2_frame:read_binary_payload(Bin, Header), + {ok, Payload, Rem} = h2_frame:read_binary_payload(Bin, Header), process_binary(Rem, undefined, <<>>, Frames ++ [{Header,Payload}]); false -> {Frames, Header, Bin} @@ -271,7 +271,7 @@ process_binary(Bin, Header, <<>>, Frames) -> L = Header#frame_header.length, case byte_size(Bin) >= L of true -> - {ok, Payload, Rem} = http2_frame:read_binary_payload(Bin, Header), + {ok, Payload, Rem} = h2_frame:read_binary_payload(Bin, Header), process_binary(Rem, undefined, <<>>, Frames ++ [{Header,Payload}]); false -> {Frames, Header, Bin} diff --git a/test/peer_test_handler.erl b/test/peer_test_handler.erl index 45ec6c34..3bf20394 100644 --- a/test/peer_test_handler.erl +++ b/test/peer_test_handler.erl @@ -2,7 +2,7 @@ -include_lib("chatterbox/include/http2.hrl"). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -26,7 +26,7 @@ init(ConnPid, StreamId) -> {ok, #state{conn_pid=ConnPid, Headers :: hpack:headers(), CallbackState :: any()) -> {ok, NewState :: any()}. on_receive_request_headers(_Headers, State=#state{conn_pid=ConnPid}) -> - {ok, Peer} = http2_connection:get_peer(ConnPid), + {ok, Peer} = h2_connection:get_peer(ConnPid), {ok, State#state{peer=Peer}}. -spec on_send_push_promise( @@ -49,6 +49,6 @@ on_request_end_stream(State=#state{conn_pid=ConnPid, ResponseHeaders = [ {<<":status">>,<<"200">>} ], - http2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), - http2_connection:send_body(ConnPid, StreamId, Body), + h2_connection:send_headers(ConnPid, StreamId, ResponseHeaders), + h2_connection:send_body(ConnPid, StreamId, Body), {ok, State}. diff --git a/test/protocol_errors_SUITE.erl b/test/protocol_errors_SUITE.erl index 0181ff13..d722ba7c 100644 --- a/test/protocol_errors_SUITE.erl +++ b/test/protocol_errors_SUITE.erl @@ -27,27 +27,27 @@ end_per_testcase(_, Config) -> no_data_frame_on_zero(Config) -> one_frame({#frame_header{length=2,type=?DATA,stream_id=0}, - http2_frame_data:new(<<1,2>>)}, Config). + h2_frame_data:new(<<1,2>>)}, Config). no_headers_frame_on_zero(Config) -> one_frame({#frame_header{length=2,type=?HEADERS,stream_id=0}, - http2_frame_headers:new(<<1,2>>)}, Config). + h2_frame_headers:new(<<1,2>>)}, Config). no_priority_frame_on_zero(Config) -> one_frame({#frame_header{length=5,type=?PRIORITY,stream_id=0}, - http2_frame_priority:new(0, 1, 1)}, Config). + h2_frame_priority:new(0, 1, 1)}, Config). no_rst_stream_frame_on_zero(Config) -> one_frame({#frame_header{length=4,type=?RST_STREAM,stream_id=0}, - http2_frame_rst_stream:new(?PROTOCOL_ERROR)}, Config). + h2_frame_rst_stream:new(?PROTOCOL_ERROR)}, Config). no_push_promise_frame_on_zero(Config) -> one_frame({#frame_header{length=2,type=?PUSH_PROMISE,stream_id=0}, - http2_frame_push_promise:new(100, <<1,2>>)}, Config). + h2_frame_push_promise:new(100, <<1,2>>)}, Config). no_continuation_frame_on_zero(Config) -> one_frame({#frame_header{length=2,type=?CONTINUATION,stream_id=0}, - http2_frame_continuation:new(<<1,2>>)}, Config). + h2_frame_continuation:new(<<1,2>>)}, Config). no_settings_frame_on_non_zero(Config) -> one_frame({#frame_header{length=0,type=?SETTINGS,stream_id=1}, @@ -55,11 +55,11 @@ no_settings_frame_on_non_zero(Config) -> no_ping_frame_on_non_zero(Config) -> one_frame({#frame_header{length=8,type=?PING,stream_id=1}, - http2_frame_ping:new(<<1:64>>)}, Config). + h2_frame_ping:new(<<1:64>>)}, Config). no_goaway_frame_on_non_zero(Config) -> one_frame({#frame_header{length=4,type=?GOAWAY,stream_id=1}, - http2_frame_goaway:new(5, ?PROTOCOL_ERROR)}, Config). + h2_frame_goaway:new(5, ?PROTOCOL_ERROR)}, Config). one_frame(Frame, _Config) -> @@ -67,8 +67,8 @@ one_frame(Frame, _Config) -> http2c:send_unaltered_frames(Client, [Frame]), Resp = http2c:wait_for_n_frames(Client, 0, 1), ct:pal("Resp: ~p", [Resp]), - ?assertEqual(1, length(Resp)), + ?assertEqual(1, (length(Resp))), [{GoAwayH, GoAway}] = Resp, - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?PROTOCOL_ERROR, http2_frame_goaway:error_code(GoAway)), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))), ok. diff --git a/test/server_connection_receive_window.erl b/test/server_connection_receive_window.erl index d9947f6f..1f69207b 100644 --- a/test/server_connection_receive_window.erl +++ b/test/server_connection_receive_window.erl @@ -1,6 +1,6 @@ -module(server_connection_receive_window). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -19,7 +19,7 @@ init(_ConnPid, _StreamId) -> {ok, #cb_static{}}. on_receive_request_headers(Headers, State) -> - http2_stream:send_window_update(65535), + h2_stream:send_window_update(65535), ct:pal("on_receive_request_headers(~p, ~p)", [Headers, State]), {ok, State#cb_static{req_headers=Headers}}. diff --git a/test/server_stream_receive_window.erl b/test/server_stream_receive_window.erl index a61234a8..60e149ad 100644 --- a/test/server_stream_receive_window.erl +++ b/test/server_stream_receive_window.erl @@ -1,6 +1,6 @@ -module(server_stream_receive_window). --behaviour(http2_stream). +-behaviour(h2_stream). -export([ init/2, @@ -19,7 +19,7 @@ init(_ConnPid, _StreamId) -> {ok, #cb_static{}}. on_receive_request_headers(Headers, State) -> - http2_stream:send_connection_window_update(65535), + h2_stream:send_connection_window_update(65535), ct:pal("on_receive_request_headers(~p, ~p)", [Headers, State]), {ok, State#cb_static{req_headers=Headers}}. diff --git a/test/settings_handshake_SUITE.erl b/test/settings_handshake_SUITE.erl index 4df20f0f..f79c3c69 100644 --- a/test/settings_handshake_SUITE.erl +++ b/test/settings_handshake_SUITE.erl @@ -42,7 +42,7 @@ times_out_on_no_ack_of_server_settings(Config) -> %% Now send client settings so the problem becomes that we do not ack ClientSettings = #settings{}, - Bin = http2_frame_settings:send(#settings{}, ClientSettings), + Bin = h2_frame_settings:send(#settings{}, ClientSettings), Transport:send(Socket, Bin), %% Settings Frame @@ -61,9 +61,9 @@ times_out_on_no_ack_of_server_settings(Config) -> ct:pal("waiting for timeout, should arrive in 5000ms"), {ok, GoAwayBin} = Transport:recv(Socket, 0, 6000), ct:pal("GoAwayBin: ~p", [GoAwayBin]), - [{GoAwayH, GoAway}] = http2_frame:from_binary(GoAwayBin), - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?SETTINGS_TIMEOUT, http2_frame_goaway:error_code(GoAway)), + [{GoAwayH, GoAway}] = h2_frame:from_binary(GoAwayBin), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?SETTINGS_TIMEOUT, (h2_frame_goaway:error_code(GoAway))), ok. protocol_error_on_never_send_client_settings(Config) -> @@ -97,9 +97,9 @@ protocol_error_on_never_send_client_settings(Config) -> {ok, GoAwayBin} = Transport:recv(Socket, 0, 6000), ct:pal("GoAwayBin: ~p", [GoAwayBin]), - [{GoAwayH, GoAway}] = http2_frame:from_binary(GoAwayBin), - ?assertEqual(?GOAWAY, GoAwayH#frame_header.type), - ?assertEqual(?SETTINGS_TIMEOUT, http2_frame_goaway:error_code(GoAway)), + [{GoAwayH, GoAway}] = h2_frame:from_binary(GoAwayBin), + ?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)), + ?assertEqual(?SETTINGS_TIMEOUT, (h2_frame_goaway:error_code(GoAway))), ok. default_setting_honored_before_ack(_Config) ->