This gem applies a patch to OpenURI to optionally allow redirections from HTTP to HTTPS, or from HTTPS to HTTP.
Here is the problem it tries to solve:
$ irb 1.9.2p320 :001 > require 'open-uri' => true 1.9.2p320 :002 > open('http://github.com') RuntimeError: redirection forbidden: http://github.com -> https://github.com/
And here is how you can use this patch to follow the redirections:
$ irb 1.9.2p320 :001 > require 'open-uri' => true > require 'open_uri_redirections' => true 1.9.2p320 :002 > open('http://github.com', :allow_safe_redirections => true) => #<File:/var/folders/...>
The patch contained in this gem adds two options to
:allow_safe_redirectionsWhen set to true, it will allow HTTP => HTTPS redirections.
:allow_unsafe_redirectionsWhen set to true, it will allow HTTPS => HTTP redirections.
Understand what you're doing
Before using this gem, read this:
Original gist URL:
Use it at your own risk!
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install open_uri_redirections
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request