rack-canonical-host 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +5 -0
- data/README.md +10 -0
- data/lib/rack/canonical_host/redirect.rb +10 -2
- data/lib/rack/canonical_host/version.rb +1 -1
- data/spec/rack/canonical_host_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35d3203952564f0ba3368443e122d7469a26e1d3
|
4
|
+
data.tar.gz: b818b81e58a6fe8a720dbc27387b783d48d94ced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a7af383aaf322c84ca2bdfc6994963ca3cb149b787cd6dec803e103d9e23857f8db48a204bb2cd77ab40740b925c5c183ac544f028bb836ed4af35ca4d5dd6
|
7
|
+
data.tar.gz: 270717db4dbf29ba4a5356fd682e01a5faef0dba3847b231394e6ffd4dc7bdb2ab659a73ad7e74a4edb94b190af190dfe9ef66adf506cf0e27dc2b83e0c67b40
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.0 (2014-04-16)
|
4
|
+
|
5
|
+
* Add `:force_ssl` option ([Jeff Carbonella][jcarbo])
|
6
|
+
|
3
7
|
## 0.0.9 (2014-02-14)
|
4
8
|
|
5
9
|
* Add `:if` option ([Nick Ostrovsky][firedev])
|
@@ -41,6 +45,7 @@
|
|
41
45
|
|
42
46
|
* Initial release ([Tyler Hunt][tylerhunt])
|
43
47
|
|
48
|
+
[jcarbo]: http://github.com/jcarbo
|
44
49
|
[finack]: http://github.com/finack
|
45
50
|
[firedev]: http://github.com/firedev
|
46
51
|
[jellybob]: http://github.com/jellybob
|
data/README.md
CHANGED
@@ -96,6 +96,15 @@ use Rack::CanonicalHost, 'example.com', if: /.*\.example\.com/
|
|
96
96
|
use Rack::CanonicalHost, 'example.ru', if: /.*\.example\.ru/
|
97
97
|
```
|
98
98
|
|
99
|
+
If you'd like to enforce the use of HTTPS, use the `:force_ssl` option:
|
100
|
+
|
101
|
+
``` ruby
|
102
|
+
use Rack::CanonicalHost, 'example.com', force_ssl: true
|
103
|
+
```
|
104
|
+
|
105
|
+
In this case, requests like `http://example.com` will be redirected to
|
106
|
+
`https://example.com`.
|
107
|
+
|
99
108
|
|
100
109
|
## Contributing
|
101
110
|
|
@@ -111,6 +120,7 @@ use Rack::CanonicalHost, 'example.ru', if: /.*\.example\.ru/
|
|
111
120
|
Thanks to the following people who have contributed patches or helpful
|
112
121
|
suggestions:
|
113
122
|
|
123
|
+
* [Jeff Carbonella](https://github.com/jcarbo)
|
114
124
|
* [Joost Schuur](https://github.com/jellybob)
|
115
125
|
* [Jon Wood](https://github.com/jellybob)
|
116
126
|
* [Peter Baker](https://github.com/finack)
|
@@ -17,12 +17,13 @@ module Rack
|
|
17
17
|
def initialize(env, host, options={})
|
18
18
|
@env = env
|
19
19
|
@host = host
|
20
|
+
@force_ssl = options[:force_ssl]
|
20
21
|
@ignore = Array(options[:ignore])
|
21
22
|
@if = Array(options[:if])
|
22
23
|
end
|
23
24
|
|
24
25
|
def canonical?
|
25
|
-
|
26
|
+
(known? && ssl?) || ignored? || !conditions_match?
|
26
27
|
end
|
27
28
|
|
28
29
|
def response
|
@@ -36,6 +37,10 @@ module Rack
|
|
36
37
|
@host.nil? || request_uri.host == @host
|
37
38
|
end
|
38
39
|
|
40
|
+
def ssl?
|
41
|
+
!@force_ssl || request_uri.scheme == "https"
|
42
|
+
end
|
43
|
+
|
39
44
|
def ignored?
|
40
45
|
@ignore && @ignore.include?(request_uri.host)
|
41
46
|
end
|
@@ -52,7 +57,10 @@ module Rack
|
|
52
57
|
private :any_regexp_match?
|
53
58
|
|
54
59
|
def new_url
|
55
|
-
request_uri.tap { |uri|
|
60
|
+
request_uri.tap { |uri|
|
61
|
+
uri.host = @host if @host
|
62
|
+
uri.scheme = "https" if @force_ssl
|
63
|
+
}.to_s
|
56
64
|
end
|
57
65
|
|
58
66
|
def request_uri
|
@@ -117,6 +117,34 @@ describe Rack::CanonicalHost do
|
|
117
117
|
|
118
118
|
end
|
119
119
|
|
120
|
+
context 'with :force_ssl option' do
|
121
|
+
let(:app) { build_app('example.com', :force_ssl => true) }
|
122
|
+
|
123
|
+
context 'with a non-ssl request' do
|
124
|
+
let(:url) { 'http://example.com/full/path' }
|
125
|
+
it { should be_redirect.to('https://example.com/full/path') }
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'with an ssl request' do
|
129
|
+
let(:url) { 'https://example.com/full/path' }
|
130
|
+
it { should_not be_redirect }
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when host is not set' do
|
134
|
+
let(:app) { build_app(nil, :force_ssl => true) }
|
135
|
+
let(:url) { 'http://example.com/full/path' }
|
136
|
+
|
137
|
+
it { should be_redirect.to('https://example.com/full/path') }
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when :forse_ssl is false' do
|
141
|
+
let(:app) { build_app('example.com', :force_ssl => false) }
|
142
|
+
let(:url) { 'http://example.com/full/path' }
|
143
|
+
|
144
|
+
it { should_not be_redirect }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
120
148
|
context 'with a block' do
|
121
149
|
let(:app) { build_app { 'example.com' } }
|
122
150
|
|
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: 0.0
|
4
|
+
version: 0.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: 2014-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|