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

Fix bug when content type header is missing #15

Open
wants to merge 3 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/simplehttp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
def request(method, url, args \\ []) do
request = %Request{args: args} = create_request(method, url, args)
{profile, args} = init_httpc(args)
args != [] && raise ArgumentError, message: "Invalid arguments: #{inspect(args)}"
{debug, args1} = Keyword.pop(args, :debug, nil)

Check warning on line 37 in lib/simplehttp.ex

View workflow job for this annotation

GitHub Actions / OTP 25.1 / Elixir 1.13.4

variable "debug" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 37 in lib/simplehttp.ex

View workflow job for this annotation

GitHub Actions / OTP 25.1 / Elixir 1.14.1

variable "debug" is unused (if the variable is not meant to be used, prefix it with an underscore)
args1 != [] && raise ArgumentError, message: "Invalid arguments: #{inspect(args1)}"
execute(%{request | args: args, profile: profile})
end

Expand Down Expand Up @@ -125,7 +126,7 @@
end

request =
if String.valid?(content_type) do
if content_type && String.valid?(content_type) do
%{request | content_type: to_charlist(content_type)}
else
request
Expand Down Expand Up @@ -277,9 +278,7 @@
defp format_headers(headers, _), do: headers

defp debug?(%Request{args: args} = request) do
case Keyword.get(args, :debug) do
nil -> request
_ -> IO.puts("Request: #{inspect(request, pretty: true)}")
end
Keyword.get(args, :debug) && IO.puts("Request: #{inspect(request, pretty: true)}")
request
end
end
Loading