-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathheader_continuation_SUITE.erl
171 lines (143 loc) · 5.87 KB
/
header_continuation_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
-module(header_continuation_SUITE).
-include("http2.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-compile([export_all]).
all() -> [
basic_continuation,
basic_continuation_end_stream_first,
bad_frame_wrong_type_between_continuations,
bad_frame_wrong_stream_between_continuations
].
init_per_testcase(_, Config) ->
Config0 = chatterbox_test_buddy:start(Config),
Config0.
end_per_testcase(_, Config) ->
chatterbox_test_buddy:stop(Config),
ok.
basic_continuation(_Config) ->
{ok, Client} = http2c:start_link(),
%% build some headers
Headers = [
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"nghttp2/0.7.7">>}
],
{ok, {HeadersBin, _NewContext}} = hpack:encode(Headers, hpack:new_context()),
<<H1:8/binary,H2:8/binary,H3/binary>> = HeadersBin,
Frames =
[
{#frame_header{length=8,type=?HEADERS,flags=?FLAG_END_STREAM,stream_id=3},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,stream_id=3},
h2_frame_continuation:new(H2)},
{#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3},
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))),
ok.
basic_continuation_end_stream_first(_Config) ->
{ok, Client} = http2c:start_link(),
%% build some headers
Headers = [
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"nghttp2/0.7.7">>}
],
{ok, {HeadersBin, _NewContext}} = hpack:encode(Headers, hpack:new_context()),
<<H1:8/binary,H2:8/binary,H3/binary>> = HeadersBin,
Frames =
[
{#frame_header{length=8,type=?HEADERS,flags=?FLAG_END_STREAM,stream_id=3},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,stream_id=3},
h2_frame_continuation:new(H2)},
{#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3},
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))),
ok.
bad_frame_wrong_type_between_continuations(_Config) ->
{ok, Client} = http2c:start_link(),
%% build some headers
Headers = [
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"nghttp2/0.7.7">>}
],
{ok, {HeadersBin, _NewContext}} = hpack:encode(Headers, hpack:new_context()),
<<H1:8/binary,H2:8/binary,H3/binary>> = HeadersBin,
Frames =
[
{#frame_header{length=8,type=?HEADERS,stream_id=3},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,stream_id=3},
h2_frame_continuation:new(H2)},
{#frame_header{length=8,type=?HEADERS,stream_id=3},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3},
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))),
Resp2 = http2c:wait_for_n_frames(Client, 0, 1),
1 = length(Resp2),
[{GoAwayH, GoAway}] = Resp2,
?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)),
?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))),
ok.
bad_frame_wrong_stream_between_continuations(_Config) ->
{ok, Client} = http2c:start_link(),
%% build some headers
Headers = [
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"nghttp2/0.7.7">>}
],
{ok, {HeadersBin, _NewContext}} = hpack:encode(Headers, hpack:new_context()),
<<H1:8/binary,H2:8/binary,H3/binary>> = HeadersBin,
Frames =
[
{#frame_header{length=8,type=?HEADERS,stream_id=3},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,stream_id=3},
h2_frame_continuation:new(H2)},
{#frame_header{length=8,type=?HEADERS,stream_id=5},
h2_frame_headers:new(H1)},
{#frame_header{length=8,type=?CONTINUATION,flags=?FLAG_END_HEADERS,stream_id=3},
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))),
Resp2 = http2c:wait_for_n_frames(Client, 0, 1),
1 = length(Resp2),
[{GoAwayH, GoAway}] = Resp2,
?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)),
?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))),
ok.