Fix numerous bugs, design issues, and documentation - #513
Merged
Conversation
Owner
|
Sorry for the delay. There were a lot of changes and most of them were in areas of the code base I haven't worked in so I had to do some reading. :) Really appreciate that you took the time to do all this. |
Contributor
Author
|
Thanks |
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, I have been working with this library for about a week now and have found some problems
HTTParty::Request#handle_deflationdoes not do anything useful. In actuality, decompression is performed byNet::HTTP.TheNet::HTTP::GenericRequestobject 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::Responseobject is instantiated, this is copied over. ThenNet::HTTPperforms 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::HTTPHeaderobject requires all keys in the@headerinstance variable to be downcased, but this code adds headers with capital letters
Resolution: Call
add_fieldas this does the correct thing without the caller having to worry about it. Use get_fields for accessHTTParty::Request#setup_digest_authresults 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.definedwhich is silly and error prone.Resolution: set
@changed_hoststofalseininitializemethod and use that valueHTTParty::Request::Headersdefines 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
@headervariable 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
@headerHTTParty::Request#encode_with_ruby_encodingrescues StandardError and completely suppresses the exception. In actuality, the only thing that can happen isEncoding.findmay raiseArgumentError. The call to#force_encodingdoesn'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.connectionis incomplete.Resolution: List all the keys that need to be checked in the
optionshash by an implementationConnectionAdapter.connectiondoes not document helper methods used by the existing implementationResolution: Add documentation about using
clean_hostmethodmethod onHTTParty::Responseresults 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 fromObjectResolution: Switch base class to
Object. Implementnil?so the object behaves likenilfor an empty response. Implementto_s. Implementdisplay.Remove un-needed implementations of other methods thatObjectprovides.Implement
respond_to_missing?instead ofrespond_to?. Usesuperinstead 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