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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7351e7d1c54f3951648e9a1b9f0468d5c631edc0
4
- data.tar.gz: dedd6608456b3b02233428832026f30ab72560d5
3
+ metadata.gz: 35d3203952564f0ba3368443e122d7469a26e1d3
4
+ data.tar.gz: b818b81e58a6fe8a720dbc27387b783d48d94ced
5
5
  SHA512:
6
- metadata.gz: 79f6fb8fab7040d6a002e5c27e521e5c2f3f35760865f3dc80c29da399a22df2bf945b768dd701b7d4709146cf0a7e6b2a9954d7e8e0a3c6063c38e5be84b052
7
- data.tar.gz: 3ea4f3d955331bf2a96471564c7ba1cf82b57805ed127aac803a646b50f23d7b5ca8b9b5883a1cde7b1358962e074ca457bb152e80d048692c1cadbd80a57adf
6
+ metadata.gz: c3a7af383aaf322c84ca2bdfc6994963ca3cb149b787cd6dec803e103d9e23857f8db48a204bb2cd77ab40740b925c5c183ac544f028bb836ed4af35ca4d5dd6
7
+ data.tar.gz: 270717db4dbf29ba4a5356fd682e01a5faef0dba3847b231394e6ffd4dc7bdb2ab659a73ad7e74a4edb94b190af190dfe9ef66adf506cf0e27dc2b83e0c67b40
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  script: bundle exec rspec
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
4
  - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.1.1
@@ -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
- known? || ignored? || !conditions_match?
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| uri.host = @host }.to_s
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class CanonicalHost
3
- VERSION = '0.0.9'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -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.9
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-03-14 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable