Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FollowRedirects throws NoMethodError on malformed Location #171

Open
graaff opened this issue Sep 13, 2017 · 4 comments
Open

FollowRedirects throws NoMethodError on malformed Location #171

graaff opened this issue Sep 13, 2017 · 4 comments

Comments

@graaff
Copy link

graaff commented Sep 13, 2017

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:https://". 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?

@iMacTia
Copy link
Member

iMacTia commented Sep 13, 2017

Perhaps the FollowRedirect module should validate that the redirected location is a valid URL before redirecting?

That totally makes sense, I'd happily review a PR that raises a particular exception in such a case 👍

@ej2015
Copy link

ej2015 commented Aug 12, 2018

How to reproduce this? I get 'ArgumentError: no HTTP request path given' with malformed redirect url.

@graaff
Copy link
Author

graaff commented Apr 2, 2021

One site where this happens is http:https://macmiep.nl/ (it redirects to https:/// so it should be fairly easy to set up another site with the same effect).

@iMacTia
Copy link
Member

iMacTia commented Apr 7, 2021

Thanks @graaff, that looks like a great use-case for a unit test!
And since this is relatively easy, I've marked it as a good first issue for anyone who would like to help out 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants