rack-canonical-host 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -13
- data/README.md +10 -7
- data/lib/rack/canonical_host/redirect.rb +9 -8
- data/lib/rack/canonical_host/version.rb +1 -1
- metadata +20 -44
- data/.gitignore +0 -18
- data/.rspec +0 -3
- data/.travis.yml +0 -21
- data/Appraisals +0 -19
- data/Gemfile +0 -3
- data/Rakefile +0 -8
- data/gemfiles/rack_1.5.gemfile +0 -7
- data/gemfiles/rack_1.5.gemfile.lock +0 -47
- data/gemfiles/rack_1.6.gemfile +0 -7
- data/gemfiles/rack_1.6.gemfile.lock +0 -47
- data/gemfiles/rack_2.0.gemfile +0 -7
- data/gemfiles/rack_2.0.gemfile.lock +0 -47
- data/gemfiles/rack_2.1.gemfile +0 -7
- data/gemfiles/rack_2.1.gemfile.lock +0 -47
- data/gemfiles/rack_2.2.gemfile +0 -7
- data/gemfiles/rack_2.2.gemfile.lock +0 -47
- data/rack-canonical-host.gemspec +0 -20
- data/spec/rack/canonical_host_spec.rb +0 -231
- data/spec/spec_helper.rb +0 -26
- data/spec/support/matchers/have_header.rb +0 -56
- data/spec/support/matchers/redirect_to.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d04ccdf68037f3995ea1a93a9f7858d5363fa9e4eae2797d6b35eb14b00e0f2
|
4
|
+
data.tar.gz: 30f80af7f437c52e4bdbe61b3a95ee560bba6250546a4b02153d11565e0a9bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b807b256f6683f3a8864e0f422208475cb03e4baa4bbce50a998000958f98b43f41deead8f400cb0ae78b9ee6b57b0bbb6d3d0504e9faf6b31db3ad13faccc
|
7
|
+
data.tar.gz: 3a7186d72cea3a465fece9c11d2e178f1e6f09fa29e39463b58b92440fba32ecc56f2ff42742f5ad1a9359f17a4bff8a2ad3344c47308fd16a71bc2abb540230
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.0 (2023-04-14)
|
4
|
+
|
5
|
+
* Add support for Rack 3.0 ([Vinny Diehl][vinnydiehl])
|
6
|
+
* Remove unneeded gem directives ([Olle Jonsson][olleolleolle])
|
7
|
+
|
8
|
+
## 1.1.0 (2021-11-10)
|
9
|
+
|
10
|
+
* Support lambda/proc on `:if` and `:ignore` options ([Sean Huber][shuber])
|
11
|
+
* Drop support for Ruby versions 2.3, 2.4, and 2.5 ([Tyler Hunt][tylerhunt])
|
12
|
+
|
3
13
|
## 1.0.0 (2020-04-16)
|
4
14
|
|
5
15
|
* Use equality to determine string matches on `:if` and `:ignore`
|
@@ -22,7 +32,7 @@
|
|
22
32
|
* Remove `:force_ssl` option in favor of using [rack-ssl][rack-ssl]
|
23
33
|
([Nathaniel Bibler][nbibler])
|
24
34
|
|
25
|
-
[rack-ssl]:
|
35
|
+
[rack-ssl]: https://rubygems.org/gems/rack-ssl
|
26
36
|
|
27
37
|
## 0.1.0 (2014-04-16)
|
28
38
|
|
@@ -69,15 +79,18 @@
|
|
69
79
|
|
70
80
|
* Initial release ([Tyler Hunt][tylerhunt])
|
71
81
|
|
72
|
-
[Aupajo]:
|
73
|
-
[finack]:
|
74
|
-
[firedev]:
|
75
|
-
[jcarbo]:
|
76
|
-
[jellybob]:
|
77
|
-
[jschuur]:
|
78
|
-
[nbibler]:
|
79
|
-
[rubymaverick]:
|
80
|
-
[
|
81
|
-
[
|
82
|
-
[
|
83
|
-
[
|
82
|
+
[Aupajo]: https://github.com/Aupajo
|
83
|
+
[finack]: https://github.com/finack
|
84
|
+
[firedev]: https://github.com/firedev
|
85
|
+
[jcarbo]: https://github.com/jcarbo
|
86
|
+
[jellybob]: https://github.com/jellybob
|
87
|
+
[jschuur]: https://github.com/jschuur
|
88
|
+
[nbibler]: https://github.com/nbibler
|
89
|
+
[rubymaverick]: https://github.com/ericallam
|
90
|
+
[shuber]: https://github.com/shuber
|
91
|
+
[squaresurf]: httpss://github.com/squaresurf
|
92
|
+
[tma]: https://github.com/tma
|
93
|
+
[tylerhunt]: https://github.com/tylerhunt
|
94
|
+
[zoso10]: https://github.com/zoso10
|
95
|
+
[olleolleolle]: https://github.com/olleolleolle
|
96
|
+
[vinnydiehl]: https://github.com/vinnydiehl
|
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://
|
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
|
-
|
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
|
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.
|
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
|
148
|
+
Copyright © 2009 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,
|
45
|
+
def any_match?(patterns, request_uri)
|
46
46
|
patterns.any? { |pattern|
|
47
47
|
case pattern
|
48
|
-
when
|
49
|
-
when
|
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
|
}
|
@@ -54,22 +55,22 @@ module Rack
|
|
54
55
|
|
55
56
|
def headers
|
56
57
|
{
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
58
|
+
'cache-control' => cache_control,
|
59
|
+
'content-type' => 'text/html',
|
60
|
+
'location' => new_url,
|
60
61
|
}.reject { |_, value| !value }
|
61
62
|
end
|
62
63
|
|
63
64
|
def enabled?
|
64
65
|
return true if conditions.empty?
|
65
66
|
|
66
|
-
any_match?(conditions, request_uri
|
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
|
73
|
+
any_match?(ignore, request_uri)
|
73
74
|
end
|
74
75
|
|
75
76
|
def known?
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Hunt
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -36,20 +36,20 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1
|
39
|
+
version: '1'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '4'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1
|
49
|
+
version: '1'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '4'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: appraisal
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,16 +68,16 @@ dependencies:
|
|
68
68
|
name: rake
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '0'
|
73
|
+
version: '13.0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '0'
|
80
|
+
version: '13.0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rspec
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,44 +92,24 @@ dependencies:
|
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '3.0'
|
95
|
-
description:
|
96
|
-
email:
|
95
|
+
description:
|
96
|
+
email:
|
97
97
|
executables: []
|
98
98
|
extensions: []
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
|
-
- ".gitignore"
|
102
|
-
- ".rspec"
|
103
|
-
- ".travis.yml"
|
104
|
-
- Appraisals
|
105
101
|
- CHANGELOG.md
|
106
|
-
- Gemfile
|
107
102
|
- LICENSE
|
108
103
|
- README.md
|
109
|
-
- Rakefile
|
110
|
-
- gemfiles/rack_1.5.gemfile
|
111
|
-
- gemfiles/rack_1.5.gemfile.lock
|
112
|
-
- gemfiles/rack_1.6.gemfile
|
113
|
-
- gemfiles/rack_1.6.gemfile.lock
|
114
|
-
- gemfiles/rack_2.0.gemfile
|
115
|
-
- gemfiles/rack_2.0.gemfile.lock
|
116
|
-
- gemfiles/rack_2.1.gemfile
|
117
|
-
- gemfiles/rack_2.1.gemfile.lock
|
118
|
-
- gemfiles/rack_2.2.gemfile
|
119
|
-
- gemfiles/rack_2.2.gemfile.lock
|
120
104
|
- lib/rack-canonical-host.rb
|
121
105
|
- lib/rack/canonical_host.rb
|
122
106
|
- lib/rack/canonical_host/redirect.rb
|
123
107
|
- lib/rack/canonical_host/version.rb
|
124
|
-
|
125
|
-
|
126
|
-
-
|
127
|
-
- spec/support/matchers/have_header.rb
|
128
|
-
- spec/support/matchers/redirect_to.rb
|
129
|
-
homepage: http://github.com/tylerhunt/rack-canonical-host
|
130
|
-
licenses: []
|
108
|
+
homepage: https://github.com/tylerhunt/rack-canonical-host
|
109
|
+
licenses:
|
110
|
+
- MIT
|
131
111
|
metadata: {}
|
132
|
-
post_install_message:
|
112
|
+
post_install_message:
|
133
113
|
rdoc_options: []
|
134
114
|
require_paths:
|
135
115
|
- lib
|
@@ -144,12 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
124
|
- !ruby/object:Gem::Version
|
145
125
|
version: '0'
|
146
126
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
148
|
-
signing_key:
|
127
|
+
rubygems_version: 3.3.26
|
128
|
+
signing_key:
|
149
129
|
specification_version: 4
|
150
130
|
summary: Rack middleware for defining a canonical host name.
|
151
|
-
test_files:
|
152
|
-
- spec/rack/canonical_host_spec.rb
|
153
|
-
- spec/spec_helper.rb
|
154
|
-
- spec/support/matchers/have_header.rb
|
155
|
-
- spec/support/matchers/redirect_to.rb
|
131
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
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
|
data/Appraisals
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
appraise 'rack-1.5' do
|
2
|
-
gem 'rack', '~> 1.5.0'
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise 'rack-1.6' do
|
6
|
-
gem 'rack', '~> 1.6.0'
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise 'rack-2.0' do
|
10
|
-
gem 'rack', '~> 2.0.0'
|
11
|
-
end
|
12
|
-
|
13
|
-
appraise 'rack-2.1' do
|
14
|
-
gem 'rack', '~> 2.1.0'
|
15
|
-
end
|
16
|
-
|
17
|
-
appraise 'rack-2.2' do
|
18
|
-
gem 'rack', '~> 2.2.0'
|
19
|
-
end
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/gemfiles/rack_1.5.gemfile
DELETED
@@ -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
|
data/gemfiles/rack_1.6.gemfile
DELETED
@@ -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
|
data/gemfiles/rack_2.0.gemfile
DELETED
@@ -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
|
data/gemfiles/rack_2.1.gemfile
DELETED
@@ -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
|
data/gemfiles/rack_2.2.gemfile
DELETED
@@ -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
|
data/rack-canonical-host.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require './lib/rack/canonical_host/version'
|
2
|
-
|
3
|
-
Gem::Specification.new do |gem|
|
4
|
-
gem.name = 'rack-canonical-host'
|
5
|
-
gem.version = Rack::CanonicalHost::VERSION
|
6
|
-
gem.summary = 'Rack middleware for defining a canonical host name.'
|
7
|
-
gem.homepage = 'http://github.com/tylerhunt/rack-canonical-host'
|
8
|
-
gem.author = 'Tyler Hunt'
|
9
|
-
|
10
|
-
gem.add_dependency 'addressable', '> 0', '< 3'
|
11
|
-
gem.add_dependency 'rack', ['>= 1.0.0', '< 3']
|
12
|
-
gem.add_development_dependency 'appraisal', '~> 2.2'
|
13
|
-
gem.add_development_dependency 'rake'
|
14
|
-
gem.add_development_dependency 'rspec', '~> 3.0'
|
15
|
-
|
16
|
-
gem.files = `git ls-files`.split($\)
|
17
|
-
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
-
gem.require_paths = ['lib']
|
20
|
-
end
|
@@ -1,231 +0,0 @@
|
|
1
|
-
RSpec.describe Rack::CanonicalHost do
|
2
|
-
let(:app_response) { [200, { 'Content-Type' => 'text/plain' }, %w(OK)] }
|
3
|
-
let(:inner_app) { lambda { |env| response } }
|
4
|
-
|
5
|
-
before do
|
6
|
-
allow(inner_app)
|
7
|
-
.to receive(:call)
|
8
|
-
.with(env)
|
9
|
-
.and_return(app_response)
|
10
|
-
end
|
11
|
-
|
12
|
-
def build_app(host=nil, options={}, inner_app=inner_app(), &block)
|
13
|
-
Rack::Builder.new do
|
14
|
-
use Rack::Lint
|
15
|
-
use Rack::CanonicalHost, host, options, &block
|
16
|
-
run inner_app
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
shared_context 'a matching request' do
|
21
|
-
context 'with a request to a matching host' do
|
22
|
-
let(:url) { 'http://example.com/full/path' }
|
23
|
-
|
24
|
-
it { should_not be_redirect }
|
25
|
-
|
26
|
-
it 'calls the inner app' do
|
27
|
-
expect(inner_app).to receive(:call).with(env)
|
28
|
-
call_app
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
shared_context 'a non-matching request' do
|
34
|
-
context 'with a request to a non-matching host' do
|
35
|
-
let(:url) { 'http://www.example.com/full/path' }
|
36
|
-
|
37
|
-
it { should redirect_to('http://example.com/full/path') }
|
38
|
-
|
39
|
-
it 'does not call the inner app' do
|
40
|
-
expect(inner_app).to_not receive(:call)
|
41
|
-
call_app
|
42
|
-
end
|
43
|
-
|
44
|
-
it { expect(response).to_not have_header('Cache-Control') }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
shared_context 'matching and non-matching requests' do
|
49
|
-
include_context 'a matching request'
|
50
|
-
include_context 'a non-matching request'
|
51
|
-
end
|
52
|
-
|
53
|
-
context '#call' do
|
54
|
-
let(:headers) { {} }
|
55
|
-
|
56
|
-
let(:app) { build_app('example.com') }
|
57
|
-
let(:env) { Rack::MockRequest.env_for(url, headers) }
|
58
|
-
|
59
|
-
def call_app
|
60
|
-
app.call(env)
|
61
|
-
end
|
62
|
-
|
63
|
-
subject(:response) { call_app }
|
64
|
-
|
65
|
-
include_context 'a matching request'
|
66
|
-
include_context 'a non-matching request'
|
67
|
-
|
68
|
-
context 'when the request has a pipe in the URL' do
|
69
|
-
let(:url) { 'https://example.com/full/path?value=withPIPE' }
|
70
|
-
|
71
|
-
before { env['QUERY_STRING'].sub!('PIPE', '|') }
|
72
|
-
|
73
|
-
it { expect { call_app }.to_not raise_error }
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when the request has JavaScript in the URL' do
|
77
|
-
let(:url) { 'http://www.example.com/full/path' }
|
78
|
-
|
79
|
-
let(:headers) {
|
80
|
-
{ 'QUERY_STRING' => '"><script>alert(73541);</script>' }
|
81
|
-
}
|
82
|
-
|
83
|
-
let(:app) { build_app('example.com') }
|
84
|
-
|
85
|
-
it 'escapes the JavaScript' do
|
86
|
-
expect(response)
|
87
|
-
.to redirect_to('http://example.com/full/path?%22%3E%3Cscript%3Ealert(73541)%3B%3C/script%3E')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'with an X-Forwarded-Host' do
|
92
|
-
let(:url) { 'http://proxy.test/full/path' }
|
93
|
-
|
94
|
-
context 'which matches the canonical host' do
|
95
|
-
let(:headers) { { 'HTTP_X_FORWARDED_HOST' => 'example.com:80' } }
|
96
|
-
|
97
|
-
include_context 'a matching request'
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'which does not match the canonical host' do
|
101
|
-
let(:headers) { { 'HTTP_X_FORWARDED_HOST' => 'www.example.com:80' } }
|
102
|
-
|
103
|
-
include_context 'a non-matching request'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'without a host' do
|
108
|
-
let(:app) { build_app(nil) }
|
109
|
-
|
110
|
-
include_context 'a matching request'
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'with :ignore option' do
|
114
|
-
context 'with string' do
|
115
|
-
let(:app) { build_app('example.com', :ignore => 'example.net') }
|
116
|
-
|
117
|
-
include_context 'a matching request'
|
118
|
-
include_context 'a non-matching request'
|
119
|
-
|
120
|
-
context 'with a request to an ignored host' do
|
121
|
-
let(:url) { 'http://example.net/full/path' }
|
122
|
-
|
123
|
-
it { should_not be_redirect }
|
124
|
-
|
125
|
-
it 'calls the inner app' do
|
126
|
-
expect(inner_app).to receive(:call).with(env)
|
127
|
-
call_app
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'with regular expression' do
|
133
|
-
let(:app) { build_app('example.com', :ignore => /ex.*\.net/) }
|
134
|
-
|
135
|
-
include_context 'a matching request'
|
136
|
-
include_context 'a non-matching request'
|
137
|
-
|
138
|
-
context 'with a request to an ignored host' do
|
139
|
-
let(:url) { 'http://example.net/full/path' }
|
140
|
-
|
141
|
-
it { should_not be_redirect }
|
142
|
-
|
143
|
-
it 'calls the inner app' do
|
144
|
-
expect(inner_app).to receive(:call).with(env)
|
145
|
-
call_app
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
context 'with :if option' do
|
152
|
-
context 'with string' do
|
153
|
-
let(:app) { build_app('www.example.com', :if => 'example.com') }
|
154
|
-
|
155
|
-
context 'with a request to a matching host' do
|
156
|
-
let(:url) { 'http://example.com/full/path' }
|
157
|
-
|
158
|
-
it { should redirect_to('http://www.example.com/full/path') }
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'with a request to a non-matching host' do
|
162
|
-
let(:url) { 'http://api.example.com/full/path' }
|
163
|
-
|
164
|
-
it { should_not be_redirect }
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'with a regular expression' do
|
169
|
-
let(:app) { build_app('example.com', :if => '.*\.example\.com') }
|
170
|
-
|
171
|
-
context 'with a request to a matching host' do
|
172
|
-
let(:url) { 'http://www.example.com/full/path' }
|
173
|
-
|
174
|
-
it { should_not redirect_to('http://example.com/full/path') }
|
175
|
-
end
|
176
|
-
|
177
|
-
context 'with a request to a non-matching host' do
|
178
|
-
let(:url) { 'http://www.example.net/full/path' }
|
179
|
-
|
180
|
-
it { should_not be_redirect }
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context 'with a :cache_control option' do
|
186
|
-
let(:url) { 'http://subdomain.example.net/full/path' }
|
187
|
-
|
188
|
-
context 'with a max-age value' do
|
189
|
-
let(:app) {
|
190
|
-
build_app('example.com', :cache_control => 'max-age=3600')
|
191
|
-
}
|
192
|
-
|
193
|
-
it {
|
194
|
-
expect(response).to have_header('Cache-Control').with('max-age=3600')
|
195
|
-
}
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'with a no-cache value' do
|
199
|
-
let(:app) { build_app('example.com', :cache_control => 'no-cache') }
|
200
|
-
|
201
|
-
it { expect(subject).to have_header('Cache-Control').with('no-cache') }
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'with a false value' do
|
205
|
-
let(:app) { build_app('example.com', :cache_control => false) }
|
206
|
-
|
207
|
-
it { expect(subject).to_not have_header('Cache-Control') }
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'with a nil value' do
|
211
|
-
let(:app) { build_app('example.com', :cache_control => false) }
|
212
|
-
|
213
|
-
it { expect(subject).to_not have_header('Cache-Control') }
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
context 'with a block' do
|
218
|
-
let(:app) { build_app { 'example.com' } }
|
219
|
-
|
220
|
-
include_context 'a matching request'
|
221
|
-
include_context 'a non-matching request'
|
222
|
-
|
223
|
-
context 'that returns nil' do
|
224
|
-
let(:app) { build_app('example.com') { nil } }
|
225
|
-
|
226
|
-
include_context 'a matching request'
|
227
|
-
include_context 'a non-matching request'
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rack/canonical_host'
|
2
|
-
|
3
|
-
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
|
4
|
-
require(file)
|
5
|
-
end
|
6
|
-
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.filter_run :focus
|
9
|
-
config.run_all_when_everything_filtered = true
|
10
|
-
|
11
|
-
config.order = :random
|
12
|
-
Kernel.srand config.seed
|
13
|
-
|
14
|
-
if config.files_to_run.one?
|
15
|
-
config.default_formatter = 'doc'
|
16
|
-
end
|
17
|
-
|
18
|
-
config.expect_with :rspec do |expectations|
|
19
|
-
expectations.syntax = :expect
|
20
|
-
end
|
21
|
-
|
22
|
-
config.mock_with :rspec do |mocks|
|
23
|
-
mocks.syntax = :expect
|
24
|
-
mocks.verify_partial_doubles = true
|
25
|
-
end
|
26
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module HaveHeader
|
2
|
-
class Matcher
|
3
|
-
def initialize(expected_header)
|
4
|
-
self.expected_header = expected_header
|
5
|
-
end
|
6
|
-
|
7
|
-
def matches?(response)
|
8
|
-
_, self.actual_headers, _ = response
|
9
|
-
|
10
|
-
if expected_value
|
11
|
-
actual_header == expected_value
|
12
|
-
else
|
13
|
-
actual_header
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def with(expected_value)
|
18
|
-
self.expected_value = expected_value
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
def description
|
23
|
-
sentence = "have header #{expected_header.inspect}"
|
24
|
-
sentence << " with #{expected_value.inspect}" if expected_value
|
25
|
-
sentence
|
26
|
-
end
|
27
|
-
|
28
|
-
def failure_message
|
29
|
-
"Expected response to #{description}"
|
30
|
-
end
|
31
|
-
|
32
|
-
def failure_message_when_negated
|
33
|
-
"Did not expect response to #{description}"
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
attr_accessor :actual_headers
|
39
|
-
attr_accessor :expected_header
|
40
|
-
attr_accessor :expected_value
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def actual_header
|
45
|
-
actual_headers[expected_header]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def have_header(name)
|
50
|
-
Matcher.new(name)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
RSpec.configure do |config|
|
55
|
-
config.include HaveHeader
|
56
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module RedirectTo
|
2
|
-
class Matcher
|
3
|
-
def initialize(expected_location)
|
4
|
-
self.expected_location = expected_location
|
5
|
-
self.expected_status_code = STATUS
|
6
|
-
end
|
7
|
-
|
8
|
-
def matches?(response)
|
9
|
-
self.actual_status_code, self.actual_headers, _ = response
|
10
|
-
|
11
|
-
status_code_matches? && location_matches?
|
12
|
-
end
|
13
|
-
|
14
|
-
def via(expected_status_code)
|
15
|
-
self.expected_status_code = expected_status_code
|
16
|
-
self
|
17
|
-
end
|
18
|
-
|
19
|
-
def description
|
20
|
-
if expected_status_code && expected_location
|
21
|
-
"redirect to #{expected_location.inspect} via #{expected_status_code}"
|
22
|
-
elsif expected_status_code
|
23
|
-
"redirect via #{expected_status_code}"
|
24
|
-
elsif expected_location
|
25
|
-
"redirect to #{expected_location.inspect}"
|
26
|
-
else
|
27
|
-
'be a redirect'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def failure_message
|
32
|
-
"Expected response to #{description}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def failure_message_when_negated
|
36
|
-
"Did not expect response to #{description}"
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
attr_accessor :actual_headers
|
42
|
-
attr_accessor :actual_status_code
|
43
|
-
attr_accessor :expected_location
|
44
|
-
attr_accessor :expected_status_code
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
LOCATION = 'Location'
|
49
|
-
STATUS = 301
|
50
|
-
|
51
|
-
def actual_location
|
52
|
-
actual_headers[LOCATION]
|
53
|
-
end
|
54
|
-
|
55
|
-
def status_code_matches?
|
56
|
-
if expected_status_code
|
57
|
-
actual_status_code == expected_status_code
|
58
|
-
else
|
59
|
-
actual_status_code.to_s =~ /^30[1237]$/
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def location_matches?
|
64
|
-
if expected_location
|
65
|
-
expected_location == actual_location
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def redirect_to(location)
|
71
|
-
Matcher.new(location)
|
72
|
-
end
|
73
|
-
|
74
|
-
def be_redirect
|
75
|
-
Matcher.new(nil).via(nil)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
RSpec.configure do |config|
|
80
|
-
config.include RedirectTo
|
81
|
-
end
|