Skip to content

Conversation

@chewbranca
Copy link
Contributor

The Content-Type response header can be crucial for properly decoding the response. This PR creates two arity variants of process_response_body and process_response_chunk for passing in the response headers, with default implementations falling back to the standard behavior by way of the one arity versions.

@chewbranca chewbranca force-pushed the pass-headers-to-process-response branch 2 times, most recently from d0abd99 to c74ec66 Compare December 8, 2017 21:31
@chewbranca
Copy link
Contributor Author

I dropped out the commit for process_response_chunk as that doesn't have access to the headers, although it seems like it might be useful to have there as well.

The test suite is failing in three places for me, but it fails the same three tests on master and on this branch.

@chewbranca
Copy link
Contributor Author

Yeah the three failures in https://travis-ci.org/myfreeweb/httpotion/jobs/313695533 are the same I'm getting on master and on this branch.

@valpackett
Copy link
Owner

https tests are broken, don't pay attention to them :)

lib/httpotion.ex Outdated
status_code: process_status_code(status_code),
headers: process_response_headers(headers),
body: process_response_body(body)
body: process_response_body(headers, body)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The headers were just processed with process_response_headers(headers), I'm not sure raw headers should be used here. Maybe extract process_response_headers(headers) into a variable and use it both in the returned headers: and in the argument to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh good call!

lib/httpotion.ex Outdated
status_code: process_status_code(status_code),
headers: process_response_headers(headers),
body: process_response_body(body)
body: process_response_body(headers, body)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same as above)

@chewbranca
Copy link
Contributor Author

Switched to using the processed headers in ce64a04, let me know if you have a preference on the temp var name or if that's sufficient.

lib/httpotion.ex Outdated
def handle_response(response) do
case response do
{ :ok, status_code, headers, body, _ } ->
headers1 = process_response_headers(headers)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resist the Erlang! You can rebind headers here rather than using versioned variable names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but we know what it's actually doing so rebinding feels dirty... but hey, that's why I asked if @myfreeweb has a preference, I can switch to rebinding if preferred.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like processed_headers would be better than headers1. Rebinding is fine too I guess.

@chewbranca chewbranca force-pushed the pass-headers-to-process-response branch from ce64a04 to 0f60cf0 Compare December 11, 2017 20:49
@chewbranca
Copy link
Contributor Author

@myfreeweb alright, I've changed the variable name to processed_headers and squashed down to a single commit.

@valpackett valpackett merged commit f3fa2f0 into valpackett:master Dec 11, 2017
@valpackett
Copy link
Owner

Great, thanks!

@chewbranca
Copy link
Contributor Author

@myfreeweb np! Any chance you could push out a new release with this in it when you get a moment?

iilyak added a commit to cloudant/couchdb that referenced this pull request Aug 19, 2019
There were couple of hacks in test/elixir/lib/couch.ex
We've got changes needed to remove them into httpotion 3.1.3.
The changes were introduced in:
- valpackett/httpotion#118
- valpackett/httpotion#130
iilyak added a commit to cloudant/couchdb that referenced this pull request Feb 4, 2020
There were couple of hacks in test/elixir/lib/couch.ex
We've got changes needed to remove them into httpotion 3.1.3.
The changes were introduced in:
- valpackett/httpotion#118
- valpackett/httpotion#130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants