rack-canonical-host 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36437f7276540d9097e0dfaccebde73e146de68039a3477013f94d2c96f5a2d9
4
- data.tar.gz: bb2183b48c3379140f7119eb410c9b9b6a64ec2dd8ed9a7e0a5a86a01ef63e76
3
+ metadata.gz: 60b35e0827776d7a2e063e985a5239bd479314bcf9c5f4e14f36d68ee995c850
4
+ data.tar.gz: 71463943b6c8707eb4a73db1f2f2e43f73539c5beddd03fd677112a13a26126b
5
5
  SHA512:
6
- metadata.gz: 797fd843b45adb8ce8abff067c04d52792fbafb2a4752120b9b3f56502dc6c5e4c51356f810831a3199a13f00df33935139ef38a5186ea6a866f0851fe6d822b
7
- data.tar.gz: d8733e910110b3dc6365ea862bbdb3e87984c34de9581adc27ce7ee3dcfc36661f1415b080845b24e74fa1eef853c1a75096b74bec65834338fb86e3760db93a
6
+ metadata.gz: a34e6a6850579a3d8f0cdd1244468b5cc5b392912879ba9733b0a76e4895eedae167f2b2219fdabc3abf8450bb60ced81141842e3ed1418ce84e6926dfd6adb1
7
+ data.tar.gz: b8256000841f0bf5798f400e642b3f93e46abec2ae3a344306b5ad84f475cefb74c38cb0499965c2dd028d7f08391c9c38de3c7a5110167b25c7e7a1d27d7a1d
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ on:
3
+ - push
4
+ - pull_request
5
+ jobs:
6
+ test:
7
+ name: Ruby ${{ matrix.ruby }} & Rack ${{ matrix.rack }}
8
+ runs-on: 'ubuntu-latest'
9
+ strategy:
10
+ matrix:
11
+ ruby:
12
+ - '3.0'
13
+ - '2.7'
14
+ - '2.6'
15
+ rack:
16
+ - '1.5'
17
+ - '1.6'
18
+ - '2.0'
19
+ - '2.1'
20
+ - '2.2'
21
+ fail-fast: false
22
+ env:
23
+ BUNDLE_GEMFILE: "gemfiles/rack_${{ matrix.rack }}.gemfile"
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ - run: bundle install
30
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -9,6 +9,7 @@ InstalledFiles
9
9
  _yardoc
10
10
  coverage
11
11
  doc
12
+ gemfiles/*.lock
12
13
  lib/bundler/man
13
14
  pkg
14
15
  rdoc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 (2021-11-10)
4
+
5
+ * Support lambda/proc on `:if` and `:ignore` options ([Sean Huber][shuber])
6
+ * Drop support for Ruby versions 2.3, 2.4, and 2.5 ([Tyler Hunt][tylerhunt])
7
+
3
8
  ## 1.0.0 (2020-04-16)
4
9
 
5
10
  * Use equality to determine string matches on `:if` and `:ignore`
@@ -77,6 +82,7 @@
77
82
  [jschuur]: http://github.com/jschuur
78
83
  [nbibler]: http://github.com/nbibler
79
84
  [rubymaverick]: http://github.com/ericallam
85
+ [shuber]: http://github.com/shuber
80
86
  [squaresurf]: https://github.com/squaresurf
81
87
  [tma]: http://github.com/tma
82
88
  [tylerhunt]: http://github.com/tylerhunt
data/README.md CHANGED
@@ -5,7 +5,7 @@ for your application. Requests for other host names will then be redirected to
5
5
  the canonical host.
6
6
 
7
7
  [![Gem Version](https://img.shields.io/gem/v/rack-canonical-host)](http://rubygems.org/gems/rack-canonical-host)
8
- [![Build Status](https://img.shields.io/travis/tylerhunt/rack-canonical-host)](https://travis-ci.org/tylerhunt/rack-canonical-host)
8
+ [![Build Status](https://github.com/tylerhunt/rack-canonical-host/actions/workflows/ci.yml/badge.svg)](https://github.com/tylerhunt/rack-canonical-host/actions/workflows/ci.yml)
9
9
  [![Code Climate](https://img.shields.io/codeclimate/maintainability/tylerhunt/rack-canonical-host)](https://codeclimate.com/github/tylerhunt/rack-canonical-host)
10
10
 
11
11
  ## Installation
@@ -66,8 +66,9 @@ Now, the middleware will only be used if a canonical host has been defined.
66
66
 
67
67
  ### Options
68
68
 
69
- If you’d like the middleware to ignore certain hosts, use the `:ignore`
70
- option, which accepts a string, a regular expression, or an array of either.
69
+ If you’d like the middleware to ignore certain hosts, use the `:ignore` option,
70
+ which accepts a string, a regular expression, a proc, or an array of those
71
+ objects.
71
72
 
72
73
  ```ruby
73
74
  use Rack::CanonicalHost, 'example.com', ignore: 'api.example.com'
@@ -89,11 +90,12 @@ end
89
90
 
90
91
  If you want it to react only on specific hosts within a multi-domain
91
92
  environment, use the `:if` option, which accepts a string, a regular
92
- expression, or an array of either.
93
+ expression, a `lambda` or `proc`, or an array of those objects.
93
94
 
94
95
  ```ruby
95
96
  use Rack::CanonicalHost, 'example.com', if: /.*\.example\.com/
96
- use Rack::CanonicalHost, 'example.ru', if: /.*\.example\.ru/
97
+ use Rack::CanonicalHost, 'example.org',
98
+ if: ->(uri) { uri.host == 'www.example.org' }
97
99
  ```
98
100
 
99
101
  ### Cache-Control
@@ -138,10 +140,11 @@ suggestions:
138
140
  * [Eric Allam](https://github.com/ericallam)
139
141
  * [Fabrizio Regini](https://github.com/freegenie)
140
142
  * [Daniel Searles](https://github.com/squaresurf)
141
-
143
+ * [Daniel Searles](https://github.com/squaresurf)
144
+ * [Sean Huber](https://github.com/shuber)
142
145
 
143
146
  ## Copyright
144
147
 
145
- Copyright © 2009-2017 Tyler Hunt.
148
+ Copyright © 2009-2021 Tyler Hunt.
146
149
 
147
150
  Released under the terms of the MIT license. See LICENSE for details.
@@ -42,11 +42,12 @@ module Rack
42
42
 
43
43
  private
44
44
 
45
- def any_match?(patterns, host)
45
+ def any_match?(patterns, request_uri)
46
46
  patterns.any? { |pattern|
47
47
  case pattern
48
- when Regexp then host =~ pattern
49
- when String then host == pattern
48
+ when Proc then pattern.call(request_uri)
49
+ when Regexp then request_uri.host =~ pattern
50
+ when String then request_uri.host == pattern
50
51
  else false
51
52
  end
52
53
  }
@@ -63,13 +64,13 @@ module Rack
63
64
  def enabled?
64
65
  return true if conditions.empty?
65
66
 
66
- any_match?(conditions, request_uri.host)
67
+ any_match?(conditions, request_uri)
67
68
  end
68
69
 
69
70
  def ignored?
70
71
  return false if ignore.empty?
71
72
 
72
- any_match?(ignore, request_uri.host)
73
+ any_match?(ignore, request_uri)
73
74
  end
74
75
 
75
76
  def known?
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class CanonicalHost
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
4
4
  gem.name = 'rack-canonical-host'
5
5
  gem.version = Rack::CanonicalHost::VERSION
6
6
  gem.summary = 'Rack middleware for defining a canonical host name.'
7
- gem.homepage = 'http://github.com/tylerhunt/rack-canonical-host'
7
+ gem.homepage = 'https://github.com/tylerhunt/rack-canonical-host'
8
8
  gem.author = 'Tyler Hunt'
9
9
 
10
10
  gem.add_dependency 'addressable', '> 0', '< 3'
@@ -1,6 +1,6 @@
1
1
  RSpec.describe Rack::CanonicalHost do
2
2
  let(:app_response) { [200, { 'Content-Type' => 'text/plain' }, %w(OK)] }
3
- let(:inner_app) { lambda { |env| response } }
3
+ let(:inner_app) { ->(env) { response } }
4
4
 
5
5
  before do
6
6
  allow(inner_app)
@@ -111,8 +111,31 @@ RSpec.describe Rack::CanonicalHost do
111
111
  end
112
112
 
113
113
  context 'with :ignore option' do
114
+ context 'with lambda/proc' do
115
+ let(:app) {
116
+ build_app(
117
+ 'example.com',
118
+ ignore: ->(uri) { uri.host == 'example.net' }
119
+ )
120
+ }
121
+
122
+ include_context 'a matching request'
123
+ include_context 'a non-matching request'
124
+
125
+ context 'with a request to an ignored host' do
126
+ let(:url) { 'http://example.net/full/path' }
127
+
128
+ it { should_not be_redirect }
129
+
130
+ it 'calls the inner app' do
131
+ expect(inner_app).to receive(:call).with(env)
132
+ call_app
133
+ end
134
+ end
135
+ end
136
+
114
137
  context 'with string' do
115
- let(:app) { build_app('example.com', :ignore => 'example.net') }
138
+ let(:app) { build_app('example.com', ignore: 'example.net') }
116
139
 
117
140
  include_context 'a matching request'
118
141
  include_context 'a non-matching request'
@@ -130,7 +153,7 @@ RSpec.describe Rack::CanonicalHost do
130
153
  end
131
154
 
132
155
  context 'with regular expression' do
133
- let(:app) { build_app('example.com', :ignore => /ex.*\.net/) }
156
+ let(:app) { build_app('example.com', ignore: /ex.*\.net/) }
134
157
 
135
158
  include_context 'a matching request'
136
159
  include_context 'a non-matching request'
@@ -149,8 +172,29 @@ RSpec.describe Rack::CanonicalHost do
149
172
  end
150
173
 
151
174
  context 'with :if option' do
175
+ context 'with a lambda/proc' do
176
+ let(:app) {
177
+ build_app(
178
+ 'www.example.com',
179
+ if: ->(uri) { uri.host == 'example.com' }
180
+ )
181
+ }
182
+
183
+ context 'with a request to a matching host' do
184
+ let(:url) { 'http://example.com/full/path' }
185
+
186
+ it { should redirect_to('http://www.example.com/full/path') }
187
+ end
188
+
189
+ context 'with a request to a non-matching host' do
190
+ let(:url) { 'http://api.example.com/full/path' }
191
+
192
+ it { should_not be_redirect }
193
+ end
194
+ end
195
+
152
196
  context 'with string' do
153
- let(:app) { build_app('www.example.com', :if => 'example.com') }
197
+ let(:app) { build_app('www.example.com', if: 'example.com') }
154
198
 
155
199
  context 'with a request to a matching host' do
156
200
  let(:url) { 'http://example.com/full/path' }
@@ -166,7 +210,7 @@ RSpec.describe Rack::CanonicalHost do
166
210
  end
167
211
 
168
212
  context 'with a regular expression' do
169
- let(:app) { build_app('example.com', :if => '.*\.example\.com') }
213
+ let(:app) { build_app('example.com', if: '.*\.example\.com') }
170
214
 
171
215
  context 'with a request to a matching host' do
172
216
  let(:url) { 'http://www.example.com/full/path' }
@@ -187,7 +231,7 @@ RSpec.describe Rack::CanonicalHost do
187
231
 
188
232
  context 'with a max-age value' do
189
233
  let(:app) {
190
- build_app('example.com', :cache_control => 'max-age=3600')
234
+ build_app('example.com', cache_control: 'max-age=3600')
191
235
  }
192
236
 
193
237
  it {
@@ -196,19 +240,19 @@ RSpec.describe Rack::CanonicalHost do
196
240
  end
197
241
 
198
242
  context 'with a no-cache value' do
199
- let(:app) { build_app('example.com', :cache_control => 'no-cache') }
243
+ let(:app) { build_app('example.com', cache_control: 'no-cache') }
200
244
 
201
245
  it { expect(subject).to have_header('Cache-Control').with('no-cache') }
202
246
  end
203
247
 
204
248
  context 'with a false value' do
205
- let(:app) { build_app('example.com', :cache_control => false) }
249
+ let(:app) { build_app('example.com', cache_control: false) }
206
250
 
207
251
  it { expect(subject).to_not have_header('Cache-Control') }
208
252
  end
209
253
 
210
254
  context 'with a nil value' do
211
- let(:app) { build_app('example.com', :cache_control => false) }
255
+ let(:app) { build_app('example.com', cache_control: false) }
212
256
 
213
257
  it { expect(subject).to_not have_header('Cache-Control') }
214
258
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-canonical-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -98,9 +98,9 @@ executables: []
98
98
  extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
+ - ".github/workflows/ci.yml"
101
102
  - ".gitignore"
102
103
  - ".rspec"
103
- - ".travis.yml"
104
104
  - Appraisals
105
105
  - CHANGELOG.md
106
106
  - Gemfile
@@ -108,15 +108,10 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - gemfiles/rack_1.5.gemfile
111
- - gemfiles/rack_1.5.gemfile.lock
112
111
  - gemfiles/rack_1.6.gemfile
113
- - gemfiles/rack_1.6.gemfile.lock
114
112
  - gemfiles/rack_2.0.gemfile
115
- - gemfiles/rack_2.0.gemfile.lock
116
113
  - gemfiles/rack_2.1.gemfile
117
- - gemfiles/rack_2.1.gemfile.lock
118
114
  - gemfiles/rack_2.2.gemfile
119
- - gemfiles/rack_2.2.gemfile.lock
120
115
  - lib/rack-canonical-host.rb
121
116
  - lib/rack/canonical_host.rb
122
117
  - lib/rack/canonical_host/redirect.rb
@@ -126,7 +121,7 @@ files:
126
121
  - spec/spec_helper.rb
127
122
  - spec/support/matchers/have_header.rb
128
123
  - spec/support/matchers/redirect_to.rb
129
- homepage: http://github.com/tylerhunt/rack-canonical-host
124
+ homepage: https://github.com/tylerhunt/rack-canonical-host
130
125
  licenses: []
131
126
  metadata: {}
132
127
  post_install_message:
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- script: bundle exec rspec
4
- sudo: false
5
-
6
- gemfile:
7
- - gemfiles/rack_1.5.gemfile
8
- - gemfiles/rack_1.6.gemfile
9
- - gemfiles/rack_2.0.gemfile
10
- - gemfiles/rack_2.1.gemfile
11
- - gemfiles/rack_2.2.gemfile
12
-
13
- rvm:
14
- - 2.3.8
15
- - 2.4.9
16
- - 2.5.8
17
- - 2.6.5
18
- - 2.7.0
19
-
20
- before_install:
21
- - gem install bundler -v 1.17.2
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rack-canonical-host (1.0.0)
5
- addressable (> 0, < 3)
6
- rack (>= 1.0.0, < 3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- appraisal (2.2.0)
14
- bundler
15
- rake
16
- thor (>= 0.14.0)
17
- diff-lcs (1.3)
18
- public_suffix (4.0.4)
19
- rack (1.5.5)
20
- rake (13.0.1)
21
- rspec (3.9.0)
22
- rspec-core (~> 3.9.0)
23
- rspec-expectations (~> 3.9.0)
24
- rspec-mocks (~> 3.9.0)
25
- rspec-core (3.9.1)
26
- rspec-support (~> 3.9.1)
27
- rspec-expectations (3.9.1)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-mocks (3.9.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-support (3.9.2)
34
- thor (1.0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal (~> 2.2)
41
- rack (~> 1.5.0)
42
- rack-canonical-host!
43
- rake
44
- rspec (~> 3.0)
45
-
46
- BUNDLED WITH
47
- 1.17.2
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rack-canonical-host (1.0.0)
5
- addressable (> 0, < 3)
6
- rack (>= 1.0.0, < 3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- appraisal (2.2.0)
14
- bundler
15
- rake
16
- thor (>= 0.14.0)
17
- diff-lcs (1.3)
18
- public_suffix (4.0.4)
19
- rack (1.6.13)
20
- rake (13.0.1)
21
- rspec (3.9.0)
22
- rspec-core (~> 3.9.0)
23
- rspec-expectations (~> 3.9.0)
24
- rspec-mocks (~> 3.9.0)
25
- rspec-core (3.9.1)
26
- rspec-support (~> 3.9.1)
27
- rspec-expectations (3.9.1)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-mocks (3.9.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-support (3.9.2)
34
- thor (1.0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal (~> 2.2)
41
- rack (~> 1.6.0)
42
- rack-canonical-host!
43
- rake
44
- rspec (~> 3.0)
45
-
46
- BUNDLED WITH
47
- 1.17.2
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rack-canonical-host (1.0.0)
5
- addressable (> 0, < 3)
6
- rack (>= 1.0.0, < 3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- appraisal (2.2.0)
14
- bundler
15
- rake
16
- thor (>= 0.14.0)
17
- diff-lcs (1.3)
18
- public_suffix (4.0.4)
19
- rack (2.0.9)
20
- rake (13.0.1)
21
- rspec (3.9.0)
22
- rspec-core (~> 3.9.0)
23
- rspec-expectations (~> 3.9.0)
24
- rspec-mocks (~> 3.9.0)
25
- rspec-core (3.9.1)
26
- rspec-support (~> 3.9.1)
27
- rspec-expectations (3.9.1)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-mocks (3.9.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-support (3.9.2)
34
- thor (1.0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal (~> 2.2)
41
- rack (~> 2.0.0)
42
- rack-canonical-host!
43
- rake
44
- rspec (~> 3.0)
45
-
46
- BUNDLED WITH
47
- 1.17.2
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rack-canonical-host (1.0.0)
5
- addressable (> 0, < 3)
6
- rack (>= 1.0.0, < 3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- appraisal (2.2.0)
14
- bundler
15
- rake
16
- thor (>= 0.14.0)
17
- diff-lcs (1.3)
18
- public_suffix (4.0.4)
19
- rack (2.1.2)
20
- rake (13.0.1)
21
- rspec (3.9.0)
22
- rspec-core (~> 3.9.0)
23
- rspec-expectations (~> 3.9.0)
24
- rspec-mocks (~> 3.9.0)
25
- rspec-core (3.9.1)
26
- rspec-support (~> 3.9.1)
27
- rspec-expectations (3.9.1)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-mocks (3.9.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-support (3.9.2)
34
- thor (1.0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal (~> 2.2)
41
- rack (~> 2.1.0)
42
- rack-canonical-host!
43
- rake
44
- rspec (~> 3.0)
45
-
46
- BUNDLED WITH
47
- 1.17.2
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rack-canonical-host (1.0.0)
5
- addressable (> 0, < 3)
6
- rack (>= 1.0.0, < 3)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.7.0)
12
- public_suffix (>= 2.0.2, < 5.0)
13
- appraisal (2.2.0)
14
- bundler
15
- rake
16
- thor (>= 0.14.0)
17
- diff-lcs (1.3)
18
- public_suffix (4.0.4)
19
- rack (2.2.2)
20
- rake (13.0.1)
21
- rspec (3.9.0)
22
- rspec-core (~> 3.9.0)
23
- rspec-expectations (~> 3.9.0)
24
- rspec-mocks (~> 3.9.0)
25
- rspec-core (3.9.1)
26
- rspec-support (~> 3.9.1)
27
- rspec-expectations (3.9.1)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-mocks (3.9.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-support (3.9.2)
34
- thor (1.0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal (~> 2.2)
41
- rack (~> 2.2.0)
42
- rack-canonical-host!
43
- rake
44
- rspec (~> 3.0)
45
-
46
- BUNDLED WITH
47
- 1.17.2