Skip to content

Commit

Permalink
Pass headers to process_response_body
Browse files Browse the repository at this point in the history
  • Loading branch information
chewbranca authored and valpackett committed Dec 11, 2017
1 parent ea1901d commit f3fa2f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/httpotion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ defmodule HTTPotion.Base do
def process_response_body(body = {:file, filename}), do: IO.iodata_to_binary(filename)
def process_response_body(body), do: IO.iodata_to_binary(body)

def process_response_body(_headers, body), do: process_response_body(body)

def process_response_chunk(body = {:file, filename}), do: IO.iodata_to_binary(filename)
def process_response_chunk(chunk = {:error, error}), do: chunk
def process_response_chunk(raw) when is_tuple(raw), do: raw
Expand Down Expand Up @@ -248,16 +250,18 @@ defmodule HTTPotion.Base do
def handle_response(response) do
case response do
{ :ok, status_code, headers, body, _ } ->
processed_headers = process_response_headers(headers)
%HTTPotion.Response{
status_code: process_status_code(status_code),
headers: process_response_headers(headers),
body: process_response_body(body)
headers: processed_headers,
body: process_response_body(processed_headers, body)
}
{ :ok, status_code, headers, body } ->
processed_headers = process_response_headers(headers)
%HTTPotion.Response{
status_code: process_status_code(status_code),
headers: process_response_headers(headers),
body: process_response_body(body)
headers: processed_headers,
body: process_response_body(processed_headers, body)
}
{ :ibrowse_req_id, id } ->
%HTTPotion.AsyncResponse{ id: id }
Expand Down
6 changes: 6 additions & 0 deletions test/httpotion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ defmodule HTTPotionTest do
send(self(), :processed_options)
super(options)
end

def process_response_body(headers, body) do
send(self(), :processed_response_body)
super(headers, body)
end
end

TestClient.head("httpbin.org/get")
assert_received :processed_url
assert_received :processed_options
assert_received :processed_response_body
end

test "asynchronous request" do
Expand Down

0 comments on commit f3fa2f0

Please sign in to comment.