lostisland/faraday-net_http

Conflicts with faraday-encoding

nbibler opened this issue · 1 comments

The Awesome Faraday repository identifies faraday-encoding as a useful middleware for forcing response encodings to match those sent by a server.

However, it seems as though following #13, this library conflicts with faraday-encoding and errors are thrown when they're both in use. Likely this is due to the following line (Encoding in this case is unscoped, if the faraday-encoding library is loaded, there's a Faraday::Encoding class that gets priority during this call):

content_charset = Encoding.find(match.captures.first)

NoMethodError:
  undefined method `find' for Faraday::Encoding:Class
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-net_http-2.0.1/lib/faraday/adapter/net_http.rb:213:in `block in encoded_body'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-net_http-2.0.1/lib/faraday/adapter/net_http.rb:212:in `match'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-net_http-2.0.1/lib/faraday/adapter/net_http.rb:212:in `encoded_body'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-net_http-2.0.1/lib/faraday/adapter/net_http.rb:73:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-encoding-0.0.5/lib/faraday/encoding.rb:12:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/middleware.rb:17:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-detailed_logger-2.5.0/lib/faraday/detailed_logger/middleware/current.rb:55:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-follow_redirects-0.3.0/lib/faraday/follow_redirects/middleware.rb:77:in `perform_with_redirection'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-follow_redirects-0.3.0/lib/faraday/follow_redirects/middleware.rb:65:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/middleware.rb:17:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/middleware.rb:17:in `call'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/rack_builder.rb:153:in `build_response'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/connection.rb:445:in `run_request'
/ruby/2.7.4/lib/ruby/gems/2.7.0/gems/faraday-2.2.0/lib/faraday/connection.rb:281:in `post'

It seems that either this library needs to anchor the ::Encoding.find call, identify that faraday-encoding is no longer useful, or find some other mechanism to avoid this issue.

Thank you @nbibler for sharing this finding. It's actually unfortunate that we ended up with the naming conflict.

Adding the :: prefix in the net_http doesn't really hurt, so we could do that to avoid any conflict.

Since you found the inconsistency and the change seems straightforward, would you like to submit a PR for this change?