Fix ethon typhoeus exception handling #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi everyone and thanks for the fabulous gem.
What is the purpose of this pull request?
This PR improves integration with Ethon and Typhoeus libraries. Sniffer is currently interfering with the behaviour of these libs on network errors, and is not parsing urls prepended with
http(s)://
correctly.What changes did you make? (overview)
NoMethodError
Sniffer is currently crashing with
NoMethodError: undefined method 'each_with_object' for nil:NilClass
if Ethon/Typhoeus request fails with any kind of network errors (host not found, timeout, etc.). However, the original behaviour of those libraries is to not raise any exceptions on.perform
/.run
respectively.The reason is
@response_headers
is empty and is returning nil after split:sniffer/lib/sniffer/adapters/ethon_adapter.rb
Lines 59 to 64 in cdd52e4
In order to prevent interfering with original libraries' behaviour, I propose another shared spec example which runs
unresolved_request
twice (hence the method instead oflet
) with and without Sniffer, and compares the error outcomes.URL parsing
URI("http://#{url}")
should becomeURI(url.start_with?(%r{https?://}) ? url : "http://#{url}")
, otherwise we have a shift in Sniffer's host and query (i.e. host equals "https", query is "//localhost:4567/?author=Matz"). Ethon and Typhoeus support both formats of the urls.Checklist