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 for hackney with_body option #103

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ erl_crash.dump
*.ez
/doc
/cover
.tool-versions
3 changes: 2 additions & 1 deletion lib/tesla/adapter/hackney.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ if Code.ensure_loaded?(:hackney) do

defp handle({:error, _} = error), do: error
defp handle({:ok, status, headers}), do: {:ok, status, headers, []}
defp handle({:ok, status, headers, ref}) do
defp handle({:ok, status, headers, ref}) when is_reference(ref) do
with {:ok, body} <- :hackney.body(ref) do
{:ok, status, headers, body}
end
end
defp handle({:ok, status, headers, body}), do: {:ok, status, headers, body}
end
end
11 changes: 11 additions & 0 deletions test/tesla/adapter/hackney_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ defmodule Tesla.Adapter.HackneyTest do
use Tesla.Adapter.TestCase.Basic, adapter: :hackney
use Tesla.Adapter.TestCase.StreamRequestBody, adapter: :hackney
use Tesla.Adapter.TestCase.SSL, adapter: :hackney

test "get with `with_body: true` option" do
defmodule Client do
use Tesla

adapter :hackney, with_body: true
end

response = Client.get("#{Tesla.Adapter.TestCase.http_url()}/ip")
assert response.status == 200
end
end