Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85711352
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/.gitignore b/.gitignore
index bc3da9d..0095ee7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
/_build
/deps
erl_crash.dump
*.ez
/doc
/cover
+.tool-versions
diff --git a/lib/tesla/adapter/hackney.ex b/lib/tesla/adapter/hackney.ex
index 7510b96..88b5adc 100644
--- a/lib/tesla/adapter/hackney.ex
+++ b/lib/tesla/adapter/hackney.ex
@@ -1,44 +1,45 @@
if Code.ensure_loaded?(:hackney) do
defmodule Tesla.Adapter.Hackney do
def call(env, opts) do
with {:ok, status, headers, body} <- request(env, opts || []) do
%{env | status: status,
headers: headers,
body: body}
end
end
defp request(env, opts) do
request(
env.method,
Tesla.build_url(env.url, env.query),
Enum.into(env.headers, []),
env.body,
opts ++ env.opts
)
end
defp request(method, url, headers, %Stream{} = body, opts), do: request_stream(method, url, headers, body, opts)
defp request(method, url, headers, body, opts) when is_function(body), do: request_stream(method, url, headers, body, opts)
defp request(method, url, headers, body, opts) do
handle :hackney.request(method, url, headers, body || '', opts)
end
defp request_stream(method, url, headers, body, opts) do
with {:ok, ref} <- :hackney.request(method, url, headers, :stream, opts) do
for data <- body, do: :ok = :hackney.send_body(ref, data)
handle :hackney.start_response(ref)
else
e -> handle(e)
end
end
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
diff --git a/test/tesla/adapter/hackney_test.exs b/test/tesla/adapter/hackney_test.exs
index 4c81ab3..19e3f84 100644
--- a/test/tesla/adapter/hackney_test.exs
+++ b/test/tesla/adapter/hackney_test.exs
@@ -1,6 +1,17 @@
defmodule Tesla.Adapter.HackneyTest do
use ExUnit.Case
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
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Sep 19, 5:09 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1768918
Default Alt Text
(2 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment