Skip to content

FollowRedirects throws NoMethodError on malformed Location #171

@graaff

Description

@graaff

In one of our projects we are checking old links, and one of them throws a NoMethodError when using the FollowRedirects middleware. This happens because the Location: is malformed and the site tries to redirect to "http://". This causes the following NoMethodError:

NoMethodError: undefined method `+' for nil:NilClass
	from /usr/lib64/ruby/2.3.0/net/http.rb:1561:in `addr_port'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1494:in `begin_transport'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1433:in `transport_request'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1407:in `request'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1400:in `block in request'
	from /usr/lib64/ruby/2.3.0/net/http.rb:853:in `start'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1398:in `request'
	from /usr/lib64/ruby/2.3.0/net/http.rb:1156:in `get'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/adapter/net_http.rb:78:in `perform_request'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/adapter/net_http.rb:38:in `block in call'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/adapter/net_http.rb:85:in `with_net_http_connection'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday-0.11.0/lib/faraday/adapter/net_http.rb:33:in `call'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday_middleware-0.11.0/lib/faraday_middleware/gzip.rb:24:in `call'
	from /usr/lib64/ruby/gems/2.3.0/gems/faraday_middleware-0.11.0/lib/faraday_middleware/response/follow_redirects.rb:78:in `perform_with_redirection'

I could catch the NoMethodError in my calling method to catch this, but I'm a bit wary to catch a generic error here. Perhaps the FollowRedirect module should validate that the redirected location is a valid URL before redirecting?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions