Repository is archived
No commit activity in last 3 years
No release in over 3 years
open-uri HTTP to HTTPS redirect support patch
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
~> 0.9.0
>= 0
 Project Readme

[]: {{{1

File        : README.md
Maintainer  : Felix C. Stegerman <flx@obfusk.net>
Date        : 2014-11-26

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

[]: }}}1

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] (https://github.com/jaimeiniesta/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

[]: ! ( vim: set tw=70 sw=2 sts=2 et fdm=marker : )