Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/tesla/adapter/ibrowse.ex b/lib/tesla/adapter/ibrowse.ex
index 023dde2..a65727d 100644
--- a/lib/tesla/adapter/ibrowse.ex
+++ b/lib/tesla/adapter/ibrowse.ex
@@ -1,25 +1,46 @@
if Code.ensure_loaded?(:ibrowse) do
defmodule Tesla.Adapter.Ibrowse 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
body = env.body || []
- handle :ibrowse.send_req(
+ handle request(
Tesla.build_url(env.url, env.query) |> to_char_list,
Enum.into(env.headers, []),
env.method,
body,
opts
)
end
+ defp request(url, headers, method, %Stream{} = body, opts) do
+ reductor = fn(item, _acc) -> {:suspend, item} end
+ {_, _, fun} = Enumerable.reduce(body, {:suspend, nil}, reductor)
+ request(url, headers, method, fun, opts)
+ end
+
+ defp request(url, headers, method, body, opts) when is_function(body) do
+ body = {&next_chunk/1, body}
+ opts = Keyword.put(opts, :transfer_encoding, :chunked)
+ request(url, headers, method, body, opts)
+ end
+
+ defp request(url, headers, method, body, opts) do
+ :ibrowse.send_req(url, headers, method, body, opts)
+ end
+
+ defp next_chunk(fun), do: parse_chunk fun.({:cont, nil})
+
+ defp parse_chunk({:suspended, item, fun}), do: {:ok, item, fun}
+ defp parse_chunk(_), do: :eof
+
defp handle({:error, {:conn_failed, error}}), do: error
defp handle(response), do: response
end
end
diff --git a/test/tesla/adapter/ibrowse_test.exs b/test/tesla/adapter/ibrowse_test.exs
index a663749..03e2457 100644
--- a/test/tesla/adapter/ibrowse_test.exs
+++ b/test/tesla/adapter/ibrowse_test.exs
@@ -1,10 +1,11 @@
defmodule IbrowseTest do
use ExUnit.Case
use Tesla.Adapter.TestCase.Basic, adapter: :ibrowse
+ use Tesla.Adapter.TestCase.StreamRequestBody, adapter: :ibrowse
use Tesla.Adapter.TestCase.SSL, adapter: :ibrowse
setup do
Application.ensure_started(:ibrowse)
:ok
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 12:40 PM (8 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55169
Default Alt Text
(2 KB)

Event Timeline