Fix ethon typhoeus exception handling#68
Open
blaze182 wants to merge 3 commits intoaderyabin:masterfrom
Open
Conversation
`NoMethodError: undefined method `each_with_object' for nil:NilClass`
Ethon and Typhoeus can accept both raw host and protocol+host. Sniffer was parsing host and query incorrectly in the second case.
|
FWIW I just ran into this while trying to use sniffer (via https://github.com/palkan/isolator/) at GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:NilClassif 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/.runrespectively.The reason is
@response_headersis 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_requesttwice (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