Skip to content

Commit 261dfc8

Browse files
committed
test: add Connection: close tests for issue #439
Add tests to verify Connection: close responses are handled correctly: - connection_close_response: basic Connection: close response - connection_close_large_body: 100KB body with Connection: close Also adds /connection-close/:size endpoint to test_http_resource. These tests confirm Connection: close handling works correctly.
1 parent 6407ac2 commit 261dfc8

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎test/hackney_integration_tests.erl‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ all_tests() ->
1717
fun not_modified_body_read_then_next_request/0,
1818
fun chunked_body_read_then_next_request/0,
1919
fun chunked_large_body_read/0,
20+
fun connection_close_response/0,
21+
fun connection_close_large_body/0,
2022
fun basic_auth_request_failed/0,
2123
fun basic_auth_request/0,
2224
fun basic_auth_url_request/0,
@@ -142,6 +144,26 @@ chunked_large_body_read() ->
142144
{ok, Body} = hackney:body(Client),
143145
?assertEqual(102400, byte_size(Body)).
144146

147+
%% Test for issue #439: Connection: close responses should not be lost
148+
%% Tests that responses with Connection: close header are received correctly
149+
connection_close_response() ->
150+
URL = url(<<"/connection-close">>),
151+
{ok, Status, Headers, Client} = hackney:request(get, URL, [], <<>>, []),
152+
?assertEqual(200, Status),
153+
%% Verify Connection: close header
154+
?assertEqual(<<"close">>, hackney_headers:get_value(<<"connection">>, hackney_headers:from_list(Headers))),
155+
{ok, Body} = hackney:body(Client),
156+
?assertEqual(<<"{\"connection\": \"close\"}">>, Body).
157+
158+
%% Test larger Connection: close response
159+
connection_close_large_body() ->
160+
URL = url(<<"/connection-close/102400">>),
161+
{ok, Status, Headers, Client} = hackney:request(get, URL, [], <<>>, [{recv_timeout, 10000}]),
162+
?assertEqual(200, Status),
163+
?assertEqual(<<"close">>, hackney_headers:get_value(<<"connection">>, hackney_headers:from_list(Headers))),
164+
{ok, Body} = hackney:body(Client),
165+
?assertEqual(102400, byte_size(Body)).
166+
145167
basic_auth_request() ->
146168
URL = url(<<"/basic-auth/username/password">>),
147169
%% Use application variable instead of per-request option

‎test/test_http_resource.erl‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ handle_request(<<"GET">>, <<"/connection-close">>, Req, State) ->
130130
}, <<"{\"connection\": \"close\"}">>, Req),
131131
{ok, Req2, State};
132132

133+
%% GET /connection-close/:size - return large body with Connection: close
134+
%% For testing issue #439 - responses with connection close sometimes lost
135+
handle_request(<<"GET">>, <<"/connection-close/", SizeBin/binary>>, Req, State) ->
136+
Size = binary_to_integer(SizeBin),
137+
Body = binary:copy(<<"X">>, Size),
138+
Req2 = cowboy_req:reply(200, #{
139+
<<"content-type">> => <<"application/octet-stream">>,
140+
<<"connection">> => <<"close">>
141+
}, Body, Req),
142+
{ok, Req2, State};
143+
133144
%% GET /inform - send 1xx informational response before final response
134145
%% Query params:
135146
%% - status: informational status code (default 103)

0 commit comments

Comments
 (0)