File        : README.md
Maintainer  : Felix C. Stegerman <[email protected]>
Date        : 2014-11-26

Copyright   : Copyright (C) 2014  Felix C. Stegerman
Version     : v0.1.3

Gem Version Build Status

Description

open_uri_w_redirect_to_https - open-uri HTTP to HTTPS redirect support patch

Unfortunately, open-uri does not accept HTTP to HTTPS redirects. This gem patches open to allow HTTP to HTTPS redirects when requested.

So instead of:

$ pry
> require 'open-uri'
> open 'http://github.com'
RuntimeError: redirection forbidden: http://github.com -> https://github.com/

you get:

$ pry
> require 'open_uri_w_redirect_to_https'
> open 'http://github.com', redirect_to_https: true
=> #<File:/tmp/open-uri...>

or:

$ pry
> require 'open_uri_w_redirect_to_https'
> OpenURI.w_redirect_to_https { open 'http://github.com' }
  # dynamically scoped in current thread
=> #<File:/tmp/open-uri...>

or:

$ pry
> require 'open_uri_w_redirect_to_https'
> OpenURI.redirect_to_https = true   # set global default
> open 'http://github.com'
=> #<File:/tmp/open-uri...>

Installation

With bundler:

# Gemfile
gem 'open_uri_w_redirect_to_https'

Otherwise:

gem install open_uri_w_redirect_to_https

Caveats

Monkey-patching is not a very robust way to fix bugs. Use at your own risk.

Q: Why should I prefer this gem to open_uri_redirections?
A: Now that open_uri_redirections (>= 0.2.0) is thread-safe, feel free to choose either based on your needs. This gem supports global and dynamic defaults, wherease open_uri_redirections supports HTTPS to HTTP (unsafe) redirects.

NB: this gem internally uses thread-local variables like Thread.current[:__open_uri_w_redirect_to_https__].

Specs & Docs

rake spec
rake coverage
rake docs

TODO

  • specs: (can we) test redirect_to_https=true w/ threads?
  • thread-safe spec: (can we) make it no longer brittle?

License

MIT [1].

References

[1] MIT License --- http://opensource.org/licenses/MIT