Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
4161-Add-test-to-check-for-Content-Length-match...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 4161-Add-test-to-check-for-Content-Length-matching-iolist.patch of Package erlang
From 67fdcff459c351a9fc4785813b61d93632e0d5f6 Mon Sep 17 00:00:00 2001 From: Tyler Hughes <artman41@gmail.com> Date: Fri, 29 Jul 2022 02:05:25 +0100 Subject: [PATCH 1/4] Add test to check for Content-Length matching iolist_size --- lib/inets/test/httpc_SUITE.erl | 60 +++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 4539ff5062..1c1e642714 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -25,6 +25,7 @@ -module(httpc_SUITE). +-include_lib("stdlib/include/assert.hrl"). -include_lib("kernel/include/file.hrl"). -include_lib("common_test/include/ct.hrl"). -include("inets_test_lib.hrl"). @@ -103,7 +104,8 @@ real_requests()-> streaming_error, inet_opts, invalid_headers, - invalid_body + invalid_body, + iolist_body ]. only_simulated() -> @@ -1113,6 +1113,63 @@ invalid_body(Config) -> end. %%------------------------------------------------------------------------- + +iolist_body(Config) -> + {ok, ListenSocket} = gen_tcp:listen(0, [{active,once}, binary]), + {ok,{_,Port}} = inet:sockname(ListenSocket), + + ProcessHeaders = + fun + F([], Acc) -> + Acc; + F([Line|Tail], Acc0) -> + Acc1 = + case binary:split(Line, <<": ">>, [trim_all]) of + [Key, Value] -> + Acc0#{Key => Value}; + _ -> + Acc0 + end, + F(Tail, Acc1) + end, + + proc_lib:spawn(fun() -> + {ok, Accept} = gen_tcp:accept(ListenSocket), + receive + {tcp, Accept, Msg} -> + ct:log("Message received: ~p", [Msg]), + [_HeadLine | HeaderLines] = binary:split(Msg, <<"\r\n">>, [global]), + Headers = ProcessHeaders(HeaderLines, #{}), + ContentLength = maps:get(<<"content-length">>, Headers, "-1"), + gen_tcp:send(Accept, [ + "HTTP/1.1 200 OK\r\n", + "\r\n", + ContentLength + ]) + after + 1000 -> + ct:fail("Timeout: did not receive packet") + end + end), + + {ok, Host} = inet:gethostname(), + URL = ?URL_START ++ Host ++ ":" ++ integer_to_list(Port), + ReqBody = [ + <<"abc">>, + <<"def">> + ], + {ok, Resp} = httpc:request(post, {URL, _Headers = [], _ContentType = "text/plain", ReqBody}, [], []), + ct:log("Got response ~p", [Resp]), + case Resp of + {{"HTTP/1.1", 200, "OK"}, [], RespBody} -> + ReqBody_ContentLength = list_to_integer([C || C <- RespBody, C =/= $\s]), + ?assertEqual(iolist_size(ReqBody), ReqBody_ContentLength); + _ -> + ct:fail("Didn't receive the correct response") + end. + + +%%------------------------------------------------------------------------- remote_socket_close(Config) when is_list(Config) -> URL = url(group_name(Config), "/just_close.html", Config), {error, socket_closed_remotely} = httpc:request(URL). -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor