@@ -20,6 +20,10 @@ all_tests() ->
2020 % fun relative_redirect_request_no_follow/0,
2121 fun relative_redirect_request_follow /0 ,
2222 fun test_duplicate_headers /0 ,
23+ fun test_post_includes_content_headers_with_body /0 ,
24+ fun test_post_includes_content_headers_with_empty_body /0 ,
25+ fun test_get_includes_content_headers_with_body /0 ,
26+ fun test_get_excludes_content_headers_with_empty_body /0 ,
2327 fun test_custom_host_headers /0 ,
2428 fun async_request /0 ,
2529 fun async_head_request /0 ,
@@ -186,6 +190,49 @@ test_custom_host_headers() ->
186190 ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
187191 ? assertEqual (<<" myhost.com" >>, proplists :get_value (<<" Host" >>, ReqHeaders )).
188192
193+ test_post_includes_content_headers_with_body () ->
194+ URL = <<" http://localhost:8000/post" >>,
195+ Body = <<" {\" test\" : \" ok\" }" >>,
196+ Options = [with_body ],
197+ {ok , 200 , _H , JsonBody } = hackney :post (URL , [], Body , Options ),
198+ Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
199+ ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
200+ ? assertEqual (<<" 15" >>, proplists :get_value (<<" Content-Length" >>, ReqHeaders )),
201+ ? assertEqual (<<" application/octet-stream" >>, proplists :get_value (<<" Content-Type" >>, ReqHeaders )).
202+
203+ test_post_includes_content_headers_with_empty_body () ->
204+ URL = <<" http://localhost:8000/post" >>,
205+ Body = <<>>,
206+ Options = [with_body ],
207+ {ok , 200 , _H , JsonBody } = hackney :post (URL , [], Body , Options ),
208+ Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
209+ ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
210+ ? assertEqual (<<" 0" >>, proplists :get_value (<<" Content-Length" >>, ReqHeaders )),
211+ ? assertEqual (<<" application/octet-stream" >>, proplists :get_value (<<" Content-Type" >>, ReqHeaders )).
212+
213+
214+ test_get_includes_content_headers_with_body () ->
215+ URL = <<" http://localhost:8000/get" >>,
216+ Body = <<" {\" test\" : \" ok\" }" >>,
217+ Options = [with_body ],
218+ {ok , 200 , _H , JsonBody } = hackney :get (URL , [], Body , Options ),
219+ Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
220+ ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
221+ ? assertEqual (<<" 15" >>, proplists :get_value (<<" Content-Length" >>, ReqHeaders )),
222+ ? assertEqual (<<" application/octet-stream" >>, proplists :get_value (<<" Content-Type" >>, ReqHeaders )).
223+
224+ test_get_excludes_content_headers_with_empty_body () ->
225+ URL = <<" http://localhost:8000/get" >>,
226+ EmptyBodies = [<<>>, [], [<<>>]],
227+ Options = [with_body ],
228+ lists :foreach (fun (Body ) ->
229+ {ok , 200 , _H , JsonBody } = hackney :get (URL , [], Body , Options ),
230+ Obj = jsone :decode (JsonBody , [{object_format , proplist }]),
231+ ReqHeaders = proplists :get_value (<<" headers" >>, Obj ),
232+ ? assertEqual (undefined , proplists :get_value (<<" Content-Type" >>, ReqHeaders )),
233+ ? assertEqual (undefined , proplists :get_value (<<" Content-Length" >>, ReqHeaders ))
234+ end , EmptyBodies ).
235+
189236test_frees_manager_ets_when_body_is_in_client () ->
190237 URL = <<" http://localhost:8000/get" >>,
191238 BeforeCount = ets :info (hackney_manager_refs , size ),
0 commit comments