Fix numerous bugs, design issues, and documentation #513
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, I have been working with this library for about a week now and have found some problems
HTTParty::Request#handle_deflation
does not do anything useful. In actuality, decompression is performed byNet::HTTP.
TheNet::HTTP::GenericRequest
object has a 'decode_content' value (boolean) that the documentation says is false if 'Accept-Encoding' is specified. This is done with a check in the '[]=' operator on the class, but this isn't called. HTTParty uses the 'initialize_http_header' method, which does not perform this check. So decode_content is always true. When theNet::HTTP::Response
object is instantiated, this is copied over. ThenNet::HTTP
performs the decompression. Not only is 'handle_deflation' dead code, there is already an implementation of this in Net::HTTPResolution: Remove 'handle_deflation' method and calls. If a caller specifies 'Accept-Encoding' header, then explicitly set it on the object so that Net::HTTP skips decompression.
@header
. TheNet::HTTPHeader
object requires all keys in the@header
instance variable to be downcased, but this code adds headers with capital letters
Resolution: Call
add_field
as this does the correct thing without the caller having to worry about it. Use get_fields for accessHTTParty::Request#setup_digest_auth
results in all requests being sent twice if the user specifies digest_auth. There is no way that this makes sense.Resolution: Check for 401 and 'www-authenticate' header when considering the response. Resend the request if the user configured digest_auth and the server supports digest_auth
HTTParty::Request#send_authorization_headers?
usesself.defined
which is silly and error prone.Resolution: set
@changed_hosts
tofalse
ininitialize
method and use that valueHTTParty::Request::Headers
defines the equality (==
) operator without considering the downcased version of the right hand side.Resolution: If the right hand side is a Net::HTTPHeader, compare against the
@header
variable of the right hand side object directly.Use SimpleDelegator to forward methods to
@header
. If the right hand side is a has, convert the hash to an instance of ourselves and performthe above comparison if the hash does not exactly equal our own
@header
HTTParty::Request#encode_with_ruby_encoding
rescues StandardError and completely suppresses the exception. In actuality, the only thing that can happen isEncoding.find
may raiseArgumentError
. The call to#force_encoding
doesn't fail, because nothing actually happens at that time.Resolution: Check 'Encoding.name_list.include?(charset)' before calling '#force_encoding'. No exception handling needed.
ConnectionAdapter.connection
is incomplete.Resolution: List all the keys that need to be checked in the
options
hash by an implementationConnectionAdapter.connection
does not document helper methods used by the existing implementationResolution: Add documentation about using
clean_host
method
method onHTTParty::Response
results in the most vexing of errors. such as stuff like thisThis doesn't make any sort of logical sense given that I have a
Response
, not a string. It looks like for some reason this class inherits from BasicObject. There is a haphazard implementation ofrespond_to?
,class
, etc. It's far simpler to just define the methods needed and inherit fromObject
Resolution: Switch base class to
Object
. Implementnil?
so the object behaves likenil
for an empty response. Implementto_s
. Implementdisplay
.Remove un-needed implementations of other methods thatObject
provides.Implement
respond_to_missing?
instead ofrespond_to?
. Usesuper
instead ofRESPOND_TO_METHODS.include?(method_name)
Reference: http://blog.marc-andre.ca/2010/11/15/methodmissing-politely/
If you would like further elaboration on any of these issues or have questions just let me know.
Here is the output from running
bundle exec rake
:https://gist.github.com/hydrogen18/23f812df0fd7679cb1694f772302f6ef