open_uri_w_redirect_to_https 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9deff2ecc9ce387ffff9e58e0363488e73a4a56
4
+ data.tar.gz: 762930ae967325ada38469f82b6860b0522ad5e8
5
+ SHA512:
6
+ metadata.gz: 67810beb05e32c9b442846230827695ce16d80c5a241736c241c42d5d8bae5af7fecb21f70e8b91d408e06f73dda5a31e826af8f60a1bd9cf560c9f733c07cdd
7
+ data.tar.gz: ac6489110783d2bb0ec7f11c27dde135da3928890000eac965cc0dedd1cac98f3058d2d4c5de9317c911e7dea241256350cce011dc52f8dc33a37ecc9bf4df00
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Felix C. Stegerman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ []: {{{1
2
+
3
+ File : README.md
4
+ Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
+ Date : 2014-11-22
6
+
7
+ Copyright : Copyright (C) 2014 Felix C. Stegerman
8
+ Version : v0.1.0
9
+
10
+ []: }}}1
11
+
12
+ [![Gem Version](https://badge.fury.io/rb/open_uri_w_redirect_to_https.png)](https://rubygems.org/gems/open_uri_w_redirect_to_https)
13
+
14
+ ## Description
15
+
16
+ open_uri_w_redirect_to_https - open-uri HTTP to HTTPS redirect support patch
17
+
18
+ Unfortunately, `open-uri` [does not accept HTTP to HTTPS
19
+ redirects](https://bugs.ruby-lang.org/issues/3719). This gem
20
+ patches `open` to allow HTTP to HTTPS redirects when requested.
21
+
22
+ So instead of:
23
+
24
+ ```bash
25
+ $ pry
26
+ > require 'open-uri'
27
+ > open 'http://github.com'
28
+ RuntimeError: redirection forbidden: http://github.com -> https://github.com/
29
+ ```
30
+
31
+ you get:
32
+
33
+ ```bash
34
+ $ pry
35
+ > require 'open_uri_w_redirect_to_https'
36
+ > open 'http://github.com', redirect_to_https: true
37
+ => #<File:/tmp/open-uri...>
38
+ ```
39
+
40
+ or:
41
+
42
+ ```bash
43
+ $ pry
44
+ > require 'open_uri_w_redirect_to_https'
45
+ > OpenURI.redirect_to_https = true # set default
46
+ > open 'http://github.com'
47
+ => #<File:/tmp/open-uri...>
48
+ ```
49
+
50
+ ## Installation
51
+
52
+ With bundler:
53
+
54
+ ```ruby
55
+ # Gemfile
56
+ gem 'open_uri_w_redirect_to_https'
57
+ ```
58
+
59
+ Otherwise:
60
+
61
+ ```bash
62
+ gem install open_uri_w_redirect_to_https
63
+ ```
64
+
65
+ ## Caveats
66
+
67
+ Monkey-patching is not a very robust way to fix bugs. Use at your
68
+ own risk.
69
+
70
+ Q: why should I prefer this gem to
71
+ [open_uri_redirections](https://github.com/jaimeiniesta/open_uri_redirections)?
72
+ <br/>
73
+ A: because this one is thread-safe.
74
+
75
+ ## Specs & Docs
76
+
77
+ ```bash
78
+ rake spec
79
+ rake coverage
80
+ rake docs
81
+ ```
82
+
83
+ ## License
84
+
85
+ MIT [1].
86
+
87
+ ## References
88
+
89
+ [1] MIT License
90
+ --- http://opensource.org/licenses/MIT
91
+
92
+ []: ! ( vim: set tw=70 sw=2 sts=2 et fdm=marker : )
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ desc 'Run specs'
2
+ task :spec do
3
+ sh 'rspec -c'
4
+ end
5
+
6
+ desc 'Run specs verbosely'
7
+ task 'spec:verbose' do
8
+ sh 'rspec -cfd'
9
+ end
10
+
11
+ desc 'Run specs verbosely, view w/ less'
12
+ task 'spec:less' do
13
+ sh 'rspec -cfd --tty | less -R'
14
+ end
15
+
16
+ desc 'Run specs w/ coverage'
17
+ task :coverage do
18
+ ENV['COVERAGE'] = 'yes'; Rake::Task['spec'].execute
19
+ end
20
+
21
+ desc 'Check for warnings'
22
+ task :warn do
23
+ reqs = %w{ config }.map { |x| "-r open_uri_w_redirect_to_https/#{x}" } * ' '
24
+ sh "ruby -w -I lib #{reqs} -e ''"
25
+ end
26
+
27
+ desc 'Check for warnings in specs'
28
+ task 'warn:spec' do
29
+ reqs = Dir['spec/**/*.rb'].sort.map { |x| "-r ./#{x}" } * ' '
30
+ sh "ruby -w -I lib -r rspec #{reqs} -e ''"
31
+ end
32
+
33
+ desc 'Check for warnings in specs (but not void context)'
34
+ task 'warn:spec:novoid' do
35
+ sh 'rake warn:spec 2>&1 | grep -v "void context"'
36
+ end
37
+
38
+ desc 'Generate docs'
39
+ task :docs do
40
+ sh 'yardoc | cat'
41
+ end
42
+
43
+ desc 'List undocumented objects'
44
+ task 'docs:undoc' do
45
+ sh 'yard stats --list-undoc'
46
+ end
47
+
48
+ desc 'Cleanup'
49
+ task :clean do
50
+ sh 'rm -rf .yardoc/ coverage/ doc/ *.gem'
51
+ end
52
+
53
+ desc 'Build SNAPSHOT gem'
54
+ task :snapshot do
55
+ v = Time.new.strftime '%Y%m%d%H%M%S'
56
+ f = 'lib/open_uri_w_redirect_to_https/version.rb'
57
+ sh "sed -ri~ 's!(SNAPSHOT)!\\1.#{v}!' #{f}"
58
+ sh 'gem build open_uri_w_redirect_to_https.gemspec'
59
+ end
60
+
61
+ desc 'Undo SNAPSHOT gem'
62
+ task 'snapshot:undo' do
63
+ sh 'git checkout -- lib/open_uri_w_redirect_to_https/version.rb'
64
+ end
@@ -0,0 +1,82 @@
1
+ # -- ; {{{1
2
+ #
3
+ # File : open_uri_w_redirect_to_https.rb
4
+ # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
+ # Date : 2014-11-22
6
+ #
7
+ # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
+ # Licence : MIT
9
+ #
10
+ # -- ; }}}1
11
+
12
+ require 'open-uri'
13
+ require 'thread'
14
+
15
+ module OpenURI
16
+
17
+ RedirectHTTPToHTTPS = { mutex: Mutex.new, default: false }
18
+
19
+ class << self
20
+ alias_method :open_uri_orig , :open_uri
21
+ alias_method :redirectable_orig?, :redirectable?
22
+
23
+ # set the `open_uri` `:redirect_to_https` default; thread safe!
24
+ def redirect_to_https=(val)
25
+ RedirectHTTPToHTTPS[:mutex].synchronize {
26
+ RedirectHTTPToHTTPS[:default] = val
27
+ }
28
+ end
29
+
30
+ # `redirectable?` patch that uses `caller` to determine whether
31
+ # HTTP to HTTPS redirection should be allowed (as well)
32
+ def redirectable?(uri1, uri2)
33
+ if caller.find { |x| x =~ /redirect_to_https/ } =~ /__WITH__/
34
+ redirectable_w_redirect_to_https? uri1, uri2
35
+ else
36
+ redirectable_orig? uri1, uri2
37
+ end
38
+ end
39
+
40
+ # `open_uri` patch that also accepts the `:redirect_to_https`
41
+ # option; when set to `true`, redirections from HTTP to HTTPS are
42
+ # allowed; for example:
43
+ #
44
+ # ```
45
+ # open('http://github.com', redirect_to_https: true) # works!
46
+ # ```
47
+ #
48
+ # you can set the default using `redirect_to_https=`
49
+ def open_uri(name, *rest, &b)
50
+ r = (o = rest.find { |x| Hash === x }) && o.delete(:redirect_to_https)
51
+ d = RedirectHTTPToHTTPS[:mutex].synchronize {
52
+ RedirectHTTPToHTTPS[:default]
53
+ }
54
+ if (r.nil? ? d : r)
55
+ open_uri__WITH__redirect_to_https name, *rest, &b
56
+ else
57
+ open_uri__WITHOUT__redirect_to_https name, *rest, &b
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ # allow everything the `redirectable?` method does as well as HTTP
64
+ # to HTTPS
65
+ def redirectable_w_redirect_to_https?(uri1, uri2)
66
+ redirectable_orig?(uri1, uri2) || \
67
+ (uri1.scheme.downcase == 'http' && uri2.scheme.downcase == 'https')
68
+ end
69
+
70
+ # just calls open_uri_orig; redirectable? matches __WITH__
71
+ def open_uri__WITH__redirect_to_https(name, *rest, &b)
72
+ open_uri_orig name, *rest, &b
73
+ end
74
+
75
+ # just calls open_uri_orig; redirectable? does't match __WITH__
76
+ def open_uri__WITHOUT__redirect_to_https(name, *rest, &b)
77
+ open_uri_orig name, *rest, &b
78
+ end
79
+ end
80
+ end
81
+
82
+ # vim: set tw=70 sw=2 sts=2 et fdm=marker :
@@ -0,0 +1,4 @@
1
+ module OpenURIWithRedirectToHttps
2
+ VERSION = '0.1.0'
3
+ DATE = '2014-11-22'
4
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../lib/open_uri_w_redirect_to_https/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'open_uri_w_redirect_to_https'
5
+ s.homepage = 'https://github.com/obfusk/open_uri_w_redirect_to_https'
6
+ s.summary = 'open-uri HTTP to HTTPS redirect support patch'
7
+
8
+ s.description = <<-END.gsub(/^ {4}/, '')
9
+ open-uri HTTP to HTTPS redirect support patch
10
+ END
11
+
12
+ s.version = OpenURIWithRedirectToHttps::VERSION
13
+ s.date = OpenURIWithRedirectToHttps::DATE
14
+
15
+ s.authors = [ 'Felix C. Stegerman' ]
16
+ s.email = %w{ flx@obfusk.net }
17
+
18
+ s.licenses = %w{ MIT }
19
+
20
+ s.files = %w{ .yardopts LICENSE README.md Rakefile } \
21
+ + %w{ open_uri_w_redirect_to_https.gemspec } \
22
+ + Dir['lib/**/*.rb']
23
+
24
+ s.add_development_dependency 'fakeweb'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'simplecov', '~> 0.9.0' # TODO
28
+ s.add_development_dependency 'yard'
29
+
30
+ s.required_ruby_version = '>= 1.9.1'
31
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_uri_w_redirect_to_https
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felix C. Stegerman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fakeweb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |
84
+ open-uri HTTP to HTTPS redirect support patch
85
+ email:
86
+ - flx@obfusk.net
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".yardopts"
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - lib/open_uri_w_redirect_to_https.rb
96
+ - lib/open_uri_w_redirect_to_https/version.rb
97
+ - open_uri_w_redirect_to_https.gemspec
98
+ homepage: https://github.com/obfusk/open_uri_w_redirect_to_https
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 1.9.1
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: open-uri HTTP to HTTPS redirect support patch
122
+ test_files: []
123
+ has_rdoc: