Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added UseLibHeaders option to allow disabling of lib headers #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/hackney_request.erl
Expand Up @@ -33,11 +33,14 @@ perform(Client0, {Method0, Path, Headers0, Body0}) ->
#client{options=Options} = Client0,

%% basic & Cookies authorization handling
UseLibHeaders = proplists:get_value(lib_headers, Options),
Cookies = proplists:get_value(cookie, Options, []),
DefaultHeaders = case proplists:get_value(basic_auth, Options) of
undefined ->
DefaultHeaders = case {proplists:get_value(basic_auth, Options), UseLibHeaders} of
{_, none} ->
[];
{undefined, _} ->
maybe_add_cookies(Cookies, [{<<"User-Agent">>, default_ua()}]);
{User, Pwd} ->
{{User, Pwd}, _} ->
User1 = hackney_bstr:to_binary(User),
Pwd1 = hackney_bstr:to_binary(Pwd),
Credentials = base64:encode(<< User1/binary, ":", Pwd1/binary >>),
Expand All @@ -55,13 +58,13 @@ perform(Client0, {Method0, Path, Headers0, Body0}) ->
),

%% add host eventually
Headers2 = maybe_add_host(Headers1, Client0#client.netloc),
Headers2 = maybe_add_host(Headers1, Client0#client.netloc, UseLibHeaders),

%% get expect headers
Expect = expectation(Headers2),

%% build headers with the body.
{FinalHeaders, ReqType, Body, Client1} = case Body0 of
{Headers3, ReqType, Body, Client1} = case Body0 of
stream ->
{Headers2, ReqType0, stream, Client0};
stream_multipart ->
Expand All @@ -81,6 +84,13 @@ perform(Client0, {Method0, Path, Headers0, Body0}) ->
handle_body(Headers2, ReqType0, Body0, Client0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the method you are bypassing when headers are disabled. Not sure what it does or what horrific things may happen to multipart streams if it isn't run. This you should definitely check 😈

end,

FinalHeaders = case UseLibHeaders of
none ->
Headers2;
_ ->
Headers3
end,

%% build final client record
Client = case ReqType of
normal ->
Expand Down Expand Up @@ -616,7 +626,9 @@ default_ua() ->
end,
<< "hackney/", Version/binary >>.

maybe_add_host(Headers0, Netloc) ->
maybe_add_host(Headers, Netloc, none) ->
Headers;
maybe_add_host(Headers0, Netloc, _) ->
{_, Headers1} = hackney_headers_new:store_new(<<"Host">>, Netloc, Headers0),
Headers1.

Expand Down