-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathhttp2_spec_5_3_SUITE.erl
127 lines (108 loc) · 3.61 KB
/
http2_spec_5_3_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
-module(http2_spec_5_3_SUITE).
-include("http2.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-compile([export_all]).
all() ->
[
sends_header_frame_that_depends_on_itself,
sends_priority_frame_that_depends_on_itself,
sends_priority_frame_that_depends_on_itself_later
].
init_per_suite(Config) ->
application:ensure_started(crypto),
chatterbox_test_buddy:start(Config).
end_per_suite(Config) ->
chatterbox_test_buddy:stop(Config),
ok.
sends_header_frame_that_depends_on_itself(_Config) ->
{ok, Client} = http2c:start_link(),
RequestHeaders =
[
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"chattercli/0.0.1 :D">>}
],
{ok, {HeadersBin, _}} = hpack:encode(RequestHeaders, hpack:new_context()),
L = byte_size(HeadersBin) + 5,
F = {
#frame_header{
stream_id=1,
length=L,
flags=?FLAG_END_HEADERS bor ?FLAG_PRIORITY,
type=?HEADERS
},
h2_frame_headers:new(
h2_frame_priority:new(0,1,1),
HeadersBin
)
},
http2c:send_unaltered_frames(Client, [F]),
Resp = http2c:wait_for_n_frames(Client, 1, 1),
ct:pal("Resp: ~p", [Resp]),
?assertEqual(1, (length(Resp))),
[{RstStreamH, RstStream}] = Resp,
?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) ->
{ok, Client} = http2c:start_link(),
PriorityFrame =
{#frame_header{
stream_id=1,
type=?PRIORITY,
length=5
},
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))),
[{RstStreamH, RstStream}] = Resp,
?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) ->
{ok, Client} = http2c:start_link(),
RequestHeaders =
[
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"chattercli/0.0.1 :D">>}
],
{ok, {HeadersBin, _}} = hpack:encode(RequestHeaders, hpack:new_context()),
L = byte_size(HeadersBin),
F = {
#frame_header{
stream_id=1,
length=L,
flags=?FLAG_END_HEADERS,% bor ?FLAG_END_STREAM,
type=?HEADERS
},
h2_frame_headers:new(HeadersBin)
},
PriorityFrame =
{#frame_header{
stream_id=1,
type=?PRIORITY,
length=5
},
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))),
[{RstStreamH, RstStream}] = Resp,
?assertEqual(?RST_STREAM, (RstStreamH#frame_header.type)),
?assertEqual(?PROTOCOL_ERROR, (h2_frame_rst_stream:error_code(RstStream))),
ok.