Skip to content

Conversation

@ankane
Copy link
Contributor

@ankane ankane commented Jan 14, 2023

Adds an option to limit the number of redirects.

URI.open(url, max_redirects: 2)

There's no limit by default for backward compatibility, but I think it'd be good for include one in a future version.

Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I like this idea, I just have a couple of requested changes.

lib/open-uri.rb Outdated
:ftp_active_mode => false,
:redirect => true,
:encoding => nil,
:max_redirects => nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set a maximum number of redirects by default to avoid infinite redirect loops. Maybe 64?

lib/open-uri.rb Outdated
uri = redirect
raise "HTTP redirection loop: #{uri}" if uri_set.include? uri.to_s
uri_set[uri.to_s] = true
raise "Too many redirects" if max_redirects && uri_set.size > max_redirects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should have a specific exception class for this, so users that want to catch this don't have to rescue RuntimeError.

@ankane
Copy link
Contributor Author

ankane commented Nov 9, 2023

Thanks @jeremyevans, updated based on the feedback.

@hsbt hsbt merged commit d5c4555 into ruby:master Dec 7, 2023
@ankane
Copy link
Contributor Author

ankane commented Dec 7, 2023

Thanks @jeremyevans and @hsbt

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants