Giter Site home page Giter Site logo

open_uri_redirections's Introduction

OpenUriRedirections Build Status Dependency Status Code Climate

This gem applies a patch to OpenURI to optionally allow redirections from HTTP to HTTPS, or from HTTPS to HTTP.

UPDATE 2019: HTTP to HTTPS is supported by native open-uri by default from Ruby 2.4.

This is based on this patch and this gem, and modified to allow redirections in both directions.

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_redirections => :safe)
=> #<File:/var/folders/...>

The patch contained in this gem adds the :allow_redirections option to OpenURI#open:

  • :allow_redirections => :safe will allow HTTP => HTTPS redirections.
  • :allow_redirections => :all will allow HTTP => HTTPS redirections and HTTPS => HTTP redirections.

Understand what you're doing

Before using this gem, read this:

Original gist URL:

https://gist.github.com/1271420

Relevant issue:

https://bugs.ruby-lang.org/issues/3719

Source here:

https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb

Thread-safe implementation adapted from this gem:

https://github.com/obfusk/open_uri_w_redirect_to_https

Use it at your own risk!

Installation

Add this line to your application's Gemfile:

gem 'open_uri_redirections'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install open_uri_redirections

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

open_uri_redirections's People

Contributors

gabceb avatar jaimeiniesta avatar johnjohndoe avatar obfusk avatar ro31337 avatar tjwallace avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.