aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-08-12 16:06:59 +0200
committerLoïc Hoguin <[email protected]>2017-08-12 16:06:59 +0200
commit24a777945ae57940f8480b4940599187bba2edcb (patch)
treeae5947ce7e582c0be5eb97891da94bb254e28103 /test
parent354c1c4ab611d3df81caac928dec1dcc888821e0 (diff)
downloadgun-24a777945ae57940f8480b4940599187bba2edcb.tar.gz
gun-24a777945ae57940f8480b4940599187bba2edcb.tar.bz2
gun-24a777945ae57940f8480b4940599187bba2edcb.zip
Remove SPDY; document HTTP/2
I just replaced "SPDY" with "HTTP/2" in the documentation. I suspect that's all that's needed, but if there's something off we can fix it later.
Diffstat (limited to 'test')
-rw-r--r--test/spdy_SUITE.erl384
-rw-r--r--test/spdy_server.erl140
-rw-r--r--test/twitter_SUITE.erl7
3 files changed, 1 insertions, 530 deletions
diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl
deleted file mode 100644
index 52068b6..0000000
--- a/test/spdy_SUITE.erl
+++ /dev/null
@@ -1,384 +0,0 @@
-%% Copyright (c) 2015, Loïc Hoguin <[email protected]>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
--module(spdy_SUITE).
--compile(export_all).
-
--import(ct_helper, [doc/1]).
-
-%% ct.
-
-all() -> [{group, spdy31}].
-
-groups() -> [{spdy31, [parallel], ct_helper:all(?MODULE)}].
-
-%% Helper functions.
-
-wait() ->
- receive after 500 -> ok end.
-
-down() ->
- receive {gun_down, _, _, _, _, _} ->
- ok
- after 5000 ->
- exit(timeout)
- end.
-
-not_down() ->
- receive {gun_down, _, _, _, _, _} ->
- exit(down)
- after 0 ->
- ok
- end.
-
-do_req_resp(ConnPid, ServerPid, ServerStreamID) ->
- StreamRef = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {syn_reply, ServerStreamID, false, <<"200">>, <<"HTTP/1.1">>, []},
- {data, ServerStreamID, true, <<"Hello world!">>}
- ]),
- receive {gun_response, _, StreamRef, _, _, _} ->
- ok
- after 5000 ->
- exit(timeout)
- end,
- ok.
-
-%% SPDY/3.1 test suite.
-
-goaway_on_close(_) ->
- doc("Send a GOAWAY when the client closes the connection (spdy-protocol-draft3-1 2.1)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- gun:close(ConnPid),
- wait(),
- [{goaway, 0, ok}] = spdy_server:stop(ServerPid),
- down().
-
-goaway_on_shutdown(_) ->
- doc("Send a GOAWAY when the client closes the connection (spdy-protocol-draft3-1 2.1)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- gun:shutdown(ConnPid),
- wait(),
- [{goaway, 0, ok}] = spdy_server:stop(ServerPid),
- down().
-
-%% @todo This probably applies to HEADERS frame or SYN_STREAM from server push.
-reject_data_on_non_existing_stream(_) ->
- doc("DATA frames received for non-existing streams must be rejected with "
- "an INVALID_STREAM stream error. (spdy-protocol-draft3-1 2.2.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- spdy_server:send(ServerPid, [
- {data, 1, true, <<"Hello world!">>}
- ]),
- wait(),
- [{rst_stream, 1, invalid_stream}] = spdy_server:stop(ServerPid).
-
-%% @todo This probably applies to HEADERS frame or SYN_STREAM from server push.
-ignore_data_on_non_existing_stream_after_goaway(_) ->
- %% Note: this is not explicitly written in the specification.
- %% However the HTTP/2 draft tells us that we can discard frames
- %% with identifiers higher than the identified last stream,
- %% which falls under this case. (draft-ietf-httpbis-http2-17 6.8)
- doc("DATA frames received for non-existing streams after a GOAWAY has been "
- "sent must be ignored. (spdy-protocol-draft3-1 2.2.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- gun:shutdown(ConnPid),
- spdy_server:send(ServerPid, [
- {data, 1, true, <<"Hello world!">>}
- ]),
- wait(),
- [{goaway, 0, ok}] = spdy_server:stop(ServerPid),
- down().
-
-%% @todo This probably applies to HEADERS frame or SYN_STREAM from server push.
-reject_data_before_syn_reply(_) ->
- doc("A DATA frame received before a SYN_REPLY must be rejected "
- "with a PROTOCOL_ERROR stream error. (spdy-protocol-draft3-1 2.2.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {data, 1, true, <<"Hello world!">>},
- {syn_reply, 1, false, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {rst_stream, 1, protocol_error}] = spdy_server:stop(ServerPid).
-
-streamid_is_odd(_) ->
- doc("Client-initiated Stream-ID must be an odd number. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- [do_req_resp(ConnPid, ServerPid, N) || N <- lists:seq(1, 5, 2)],
- Rec = spdy_server:stop(ServerPid),
- true = length(Rec) =:= length([ok || {syn_stream, StreamID, _, _, _, _, _, _, _, _, _, _} <- Rec, StreamID rem 2 =:= 1]).
-
-reject_streamid_0(_) ->
- doc("The Stream-ID 0 is not valid and must be rejected with a PROTOCOL_ERROR session error. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {syn_stream, 0, 1, true, true, 0, <<"GET">>, <<"https">>, ["localhost:", integer_to_binary(Port)], "/a", <<"HTTP/1.1">>, []},
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {goaway, 0, protocol_error}] = spdy_server:stop(ServerPid),
- down().
-
-streamid_increases_monotonically(_) ->
- doc("The Stream-ID must increase monotonically. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- Expected = [1, 3, 5, 7, 9],
- [do_req_resp(ConnPid, ServerPid, N) || N <- Expected],
- wait(),
- Rec = spdy_server:stop(ServerPid),
- Expected = [StreamID || {syn_stream, StreamID, _, _, _, _, _, _, _, _, _, _} <- Rec].
-
-streamid_does_not_wrap(_) ->
- doc("Stream-ID must not wrap. Reconnect when all Stream-IDs are exhausted. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- MaxClientStreamID = 2147483647,
- sys:replace_state(ConnPid, fun({loop, State}) ->
- %% Replace the next stream_id value to the maximum allowed value.
- {loop, setelement(11, State, setelement(9, element(11, State), MaxClientStreamID))}
- end),
- do_req_resp(ConnPid, ServerPid, MaxClientStreamID),
- %% Gun has exhausted all Stream-IDs and should now reconnect.
- {ok, spdy} = gun:await_up(ConnPid),
- %% Check that the next request is on a new connection.
- _ = gun:get(ConnPid, "/"),
- [{syn_stream, 1, _, _, _, _, _, _, _, _, _, _}] = spdy_server:stop(ServerPid).
-
-reject_syn_stream_decreasing_streamid(_) ->
- doc("Reject a decreasing Stream-ID with a PROTOCOL_ERROR session error. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- Host = ["localhost:", integer_to_binary(Port)],
- spdy_server:send(ServerPid, [
- {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/a", <<"HTTP/1.1">>, []},
- {syn_stream, 6, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/b", <<"HTTP/1.1">>, []},
- {syn_stream, 4, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/c", <<"HTTP/1.1">>, []},
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {goaway, 0, protocol_error}] = spdy_server:stop(ServerPid),
- down().
-
-reject_stream_duplicate_streamid(_) ->
- doc("Reject duplicate Stream-ID with a PROTOCOL_ERROR session error. (spdy-protocol-draft3-1 2.3.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- Host = ["localhost:", integer_to_binary(Port)],
- spdy_server:send(ServerPid, [
- {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/a", <<"HTTP/1.1">>, []},
- {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/b", <<"HTTP/1.1">>, []},
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {goaway, 2, protocol_error}] = spdy_server:stop(ServerPid),
- down().
-
-dont_send_frames_after_flag_fin(_) ->
- doc("Do not send frames after sending FLAG_FIN. (spdy-protocol-draft3-1 2.3.6)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- %% Send a POST frame with no content header so that Gun sets FLAG_FIN,
- %% then try sending data. Gun should reject this second call.
- StreamRef = gun:post(ConnPid, "/", []),
- gun:data(ConnPid, StreamRef, false, <<"Hello world!">>),
- receive {gun_error, ConnPid, StreamRef, _} ->
- ok
- after 5000 ->
- exit(timeout)
- end,
- wait(),
- [{syn_stream, _, _, _, _, _, _, _, _, _, _, _}] = spdy_server:stop(ServerPid).
-
-allow_window_update_after_flag_fin(_) ->
- doc("WINDOW_UPDATE is allowed when the stream is half-closed. (spdy-protocol-draft3-1 2.3.6)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {window_update, 1, 1024}
- ]),
- wait(),
- [{syn_stream, _, _, _, _, _, _, _, _, _, _, _}] = spdy_server:stop(ServerPid).
-
-%% @todo This probably applies to HEADERS frame or SYN_STREAM from server push.
-reject_data_on_half_closed_stream(_) ->
- doc("Data frames sent on a half-closed stream must be rejected "
- "with a STREAM_ALREADY_CLOSED stream error. (spdy-protocol-draft3-1 2.3.6)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- %% Send a POST frame with a content header so that Gun leaves this
- %% stream alive after the server sends the reply.
- _ = gun:post(ConnPid, "/", [{<<"content-length">>, <<"5">>}]),
- spdy_server:send(ServerPid, [
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []},
- {data, 1, true, <<"Hello world!">>}
- ]),
- wait(),
- [_, {rst_stream, 1, stream_already_closed}] = spdy_server:stop(ServerPid).
-
-%% @todo This probably applies to HEADERS frame or SYN_STREAM from server push.
-reject_data_on_closed_stream(_) ->
- doc("Data frames sent on a closed stream must be rejected "
- "with a PROTOCOL_ERROR stream error. (spdy-protocol-draft3-1 2.3.7)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- %% Send a GET frame so that the stream is closed when the server replies.
- _ = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []},
- {data, 1, true, <<"Hello world!">>}
- ]),
- wait(),
- [_, {rst_stream, 1, protocol_error}] = spdy_server:stop(ServerPid).
-
-%% @todo We need to test that we do the right thing when the server sends a GOAWAY.
-goaway_last_good_streamid(_) ->
- doc("The GOAWAY frame must contain the Stream-ID of the last recently "
- "received stream from the remote endpoint. (spdy-protocol-draft3-1 2.4.1)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- Host = ["localhost:", integer_to_binary(Port)],
- spdy_server:send(ServerPid, [
- {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/a", <<"HTTP/1.1">>, []},
- {syn_stream, 4, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/c", <<"HTTP/1.1">>, []},
- {syn_stream, 6, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/b", <<"HTTP/1.1">>, []},
- {syn_reply, 0, true, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {goaway, 6, protocol_error}] = spdy_server:stop(ServerPid),
- down().
-
-dont_send_rst_stream_on_rst_stream(_) ->
- doc("An endpoint must not send an RST_STREAM in response to an RST_STREAM. (spdy-protocol-draft3-1 2.4.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {rst_stream, 1, refused_stream}
- ]),
- wait(),
- %% No RST_STREAM was received; only SYN_STREAM.
- [_] = spdy_server:stop(ServerPid),
- not_down().
-
-coalesce_multiple_identical_rst_stream(_) ->
- doc("Do not send multiple identical RST_STREAM in succession. (spdy-protocol-draft3-1 2.4.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- spdy_server:send(ServerPid, [
- {data, 1, true, <<"Hello ">>},
- {data, 1, true, <<"world!">>}
- ]),
- wait(),
- [{rst_stream, 1, invalid_stream}] = spdy_server:stop(ServerPid).
-
-%% @todo I am not sure how to adequately test that we don't send bad flags.
-syn_stream_ignore_unknown_flags(_) ->
- %% Note: this is not explicitly written in the specification.
- %% However the HTTP/2 draft tells us to ignore unknown flags.
- %% (draft-ietf-httpbis-http2-17 4.1)
- doc("Unknown flags must be ignored. (spdy-protocol-draft3-1 2.6.1)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- %% Build a SYN_STREAM frame with all flag bits set to 1.
- << Before:32/bits, _:8, After/bits >> = iolist_to_binary(cow_spdy:syn_stream(cow_spdy:deflate_init(),
- 2, 1, true, true, 0, <<"GET">>, <<"https">>, ["localhost:", integer_to_binary(Port)], "/a", <<"HTTP/1.1">>, [])),
- Frame = << Before/bits, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, After/bits >>,
- spdy_server:send_raw(ServerPid, Frame),
- wait(),
- [_] = spdy_server:stop(ServerPid).
-
-reject_associated_to_streamid_0(_) ->
- doc("A non-zero Associated-To-Stream-ID sent by the server must "
- "be rejected with a PROTOCOL_ERROR session error. (spdy-protocol-draft3-1 2.6.1)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- Host = ["localhost:", integer_to_binary(Port)],
- spdy_server:send(ServerPid, [
- {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/a", <<"HTTP/1.1">>, []},
- {syn_stream, 4, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/c", <<"HTTP/1.1">>, []},
- {syn_stream, 6, 0, true, true, 0, <<"GET">>, <<"https">>, Host, "/b", <<"HTTP/1.1">>, []},
- {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {goaway, 4, protocol_error}] = spdy_server:stop(ServerPid),
- down().
-
-syn_reply_ignore_unknown_flags(_) ->
- %% Note: this is not explicitly written in the specification.
- %% However the HTTP/2 draft tells us to ignore unknown flags.
- %% (draft-ietf-httpbis-http2-17 4.1)
- doc("Unknown flags must be ignored. (spdy-protocol-draft3-1 2.6.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- %% Build a SYN_REPLY frame with all flag bits set to 1.
- << Before:32/bits, _:8, After/bits >> = iolist_to_binary(cow_spdy:syn_reply(cow_spdy:deflate_init(),
- 1, true, <<"200">>, <<"HTTP/1.1">>, [])),
- Frame = << Before/bits, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:1, After/bits >>,
- spdy_server:send_raw(ServerPid, Frame),
- wait(),
- [_] = spdy_server:stop(ServerPid).
-
-reject_duplicate_syn_reply(_) ->
- doc("Reception of multiple SYN_REPLY for the same Stream-ID must "
- "be rejected with a STREAM_IN_USE stream error. (spdy-protocol-draft3-1 2.6.2)"),
- {ok, ServerPid, Port} = spdy_server:start_link(),
- {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
- {ok, spdy} = gun:await_up(ConnPid),
- _ = gun:get(ConnPid, "/"),
- Host = ["localhost:", integer_to_binary(Port)],
- spdy_server:send(ServerPid, [
- {syn_reply, 1, false, <<"200">>, <<"HTTP/1.1">>, []},
- {syn_reply, 1, false, <<"200">>, <<"HTTP/1.1">>, []}
- ]),
- wait(),
- [_, {rst_stream, 1, stream_in_use}] = spdy_server:stop(ServerPid).
diff --git a/test/spdy_server.erl b/test/spdy_server.erl
deleted file mode 100644
index deec356..0000000
--- a/test/spdy_server.erl
+++ /dev/null
@@ -1,140 +0,0 @@
-%% Copyright (c) 2015, Loïc Hoguin <[email protected]>
-%%
-%% Permission to use, copy, modify, and/or distribute this software for any
-%% purpose with or without fee is hereby granted, provided that the above
-%% copyright notice and this permission notice appear in all copies.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
--module(spdy_server).
--behaviour(gen_server).
-
-%% API.
--export([start_link/0]).
--export([stop/1]).
--export([send/2]).
--export([send_raw/2]).
-
-%% gen_server.
--export([init/1]).
--export([handle_call/3]).
--export([handle_cast/2]).
--export([handle_info/2]).
--export([terminate/2]).
--export([code_change/3]).
-
--type recording() :: [tuple()].
-
--record(state, {
- owner = undefined :: pid(),
- recording = [] :: recording(),
- state_name = listen :: listen | record,
- socket = undefined :: ssl:sslsocket(),
- zdef = undefined :: zlib:zstream(),
- zinf = undefined :: zlib:zstream(),
- buffer = <<>> :: binary()
-}).
-
-%% API.
-
--spec start_link() -> {ok, pid()}.
-start_link() ->
- {ok, Pid} = gen_server:start_link(?MODULE, [self()], []),
- receive {port, Pid, Port} ->
- {ok, Pid, Port}
- after 5000 ->
- exit(timeout)
- end.
-
--spec stop(pid()) -> recording().
-stop(Pid) ->
- gen_server:call(Pid, stop).
-
-send(Pid, Frames) ->
- gen_server:call(Pid, {send, Frames}).
-
-send_raw(Pid, Data) ->
- gen_server:call(Pid, {send_raw, Data}).
-
-%% gen_server.
-
-init([Owner]) ->
- Opts = ct_helper:get_certs_from_ets(),
- {ok, LSocket} = ssl:listen(0, [binary, {active, false}, {nodelay, true},
- {next_protocols_advertised, [<<"spdy/3.1">>, <<"spdy/3">>]}|Opts]),
- {ok, {_, Port}} = ssl:sockname(LSocket),
- Owner ! {port, self(), Port},
- self() ! listen,
- Zdef = cow_spdy:deflate_init(),
- Zinf = cow_spdy:inflate_init(),
- {ok, #state{owner=Owner, socket=LSocket, zdef=Zdef, zinf=Zinf}}.
-
-handle_call({send, Frames}, {Owner, _}, State=#state{owner=Owner, socket=Socket, zdef=Zdef}) ->
- do_send(Frames, Socket, Zdef),
- {reply, ok, State};
-handle_call({send_raw, Data}, {Owner, _}, State=#state{owner=Owner, socket=Socket}) ->
- ssl:send(Socket, Data),
- {reply, ok, State};
-handle_call(stop, {Owner, _}, State=#state{owner=Owner, recording=Recording}) ->
- {stop, normal, lists:reverse(Recording), State};
-handle_call(_Request, _From, State) ->
- {reply, ignored, State}.
-
-handle_cast(_Msg, State) ->
- {noreply, State}.
-
-handle_info(listen, State=#state{state_name=listen, socket=LSocket}) ->
- {ok, CSocket} = ssl:transport_accept(LSocket, 5000),
- ok = ssl:ssl_accept(CSocket, 5000),
- ok = ssl:setopts(CSocket, [{active, once}]),
- {noreply, State#state{state_name=record, socket=CSocket}};
-handle_info({ssl, Socket, Data}, State=#state{state_name=record, socket=Socket, buffer=Buffer}) ->
- ok = ssl:setopts(Socket, [{active, once}]),
- State2 = handle_data(<< Buffer/binary, Data/binary >>, State),
- {noreply, State2};
-%% @todo ssl_closed ssl_error
-handle_info(_Info, State) ->
- {noreply, State}.
-
-terminate(_Reason, _State) ->
- ok.
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
-
-%% Internal.
-
-do_send([], _, _) ->
- ok;
-do_send([{syn_stream, StreamID, AssocToStreamID, IsFin, IsUnidirectional, Priority,
- Method, Scheme, Host, Path, Version, Headers}|Tail], Socket, Zdef) ->
- ssl:send(Socket, cow_spdy:syn_stream(Zdef, StreamID, AssocToStreamID, IsFin, IsUnidirectional, Priority,
- Method, Scheme, Host, Path, Version, Headers)),
- do_send(Tail, Socket, Zdef);
-do_send([{syn_reply, StreamID, IsFin, Status, Version, Headers}|Tail], Socket, Zdef) ->
- ssl:send(Socket, cow_spdy:syn_reply(Zdef, StreamID, IsFin, Status, Version, Headers)),
- do_send(Tail, Socket, Zdef);
-do_send([{rst_stream, StreamID, Status}|Tail], Socket, Zdef) ->
- ssl:send(Socket, cow_spdy:rst_stream(StreamID, Status)),
- do_send(Tail, Socket, Zdef);
-do_send([{window_update, StreamID, DeltaWindowSize}|Tail], Socket, Zdef) ->
-%% @todo ssl:send(Socket, cow_spdy:window_update(StreamID, DeltaWindowSize)),
- do_send(Tail, Socket, Zdef);
-do_send([{data, StreamID, IsFin, Data}|Tail], Socket, Zdef) ->
- ssl:send(Socket, cow_spdy:data(StreamID, IsFin, Data)),
- do_send(Tail, Socket, Zdef).
-
-handle_data(Data, State=#state{recording=Recording, zinf=Zinf}) ->
- case cow_spdy:split(Data) of
- {true, ParsedFrame, Rest} ->
- Frame = cow_spdy:parse(ParsedFrame, Zinf),
- handle_data(Rest, State#state{recording=[Frame|Recording]});
- false ->
- State#state{buffer=Data}
- end.
diff --git a/test/twitter_SUITE.erl b/test/twitter_SUITE.erl
index 6cd53c4..84307a2 100644
--- a/test/twitter_SUITE.erl
+++ b/test/twitter_SUITE.erl
@@ -16,7 +16,7 @@
-compile(export_all).
all() ->
- [http, http2, spdy].
+ [http, http2].
http(_) ->
{ok, Pid} = gun:open("twitter.com", 443, #{protocols => [http]}),
@@ -28,11 +28,6 @@ http2(_) ->
{ok, http2} = gun:await_up(Pid),
common(Pid).
-spdy(_) ->
- {ok, Pid} = gun:open("twitter.com", 443, #{protocols => [spdy]}),
- {ok, spdy} = gun:await_up(Pid),
- common(Pid).
-
common(Pid) ->
Ref = gun:get(Pid, "/"),
receive