rack-www 2.2.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da7f0cfe7b164575cae38adb196629c11f18f6a7
4
- data.tar.gz: e7d06b79e38106649e038ef948ebe504927072de
3
+ metadata.gz: 151b5d3afad9d26db8298ca10ffe0bcebb96f84a
4
+ data.tar.gz: adb3b36ed144b19330806ee0d20404ecebe5d247
5
5
  SHA512:
6
- metadata.gz: f9aee65608b0332c10002c0302bba3888878154829f3c54325879a0658d23ea5d95786ce9e3fd9a6d1012c7752cd52c375bf87b2d8414c135b3ee512ade5857a
7
- data.tar.gz: e67fe65e9ec3c270b0ebddf5081762e0c3599e392ff47d42ab033c1f0365224d15afadbb693aff827e099644547835f32b3f4f5515cd7e689434d19e3ca4773f
6
+ metadata.gz: 75c3b09eb9cfbf3526a05c6de1e2b0db714985ff2b9fbc01f5162225d1d0d3b558e9f5b68f008927d41cd5edfe574219ad7d329c9c899fe59d0d5c7a31610420
7
+ data.tar.gz: 45af1d84526805b50dd59c2c9adcfcf3219d2afef283be53c6484fb7266a86536af244628bcae1e3f3afd353115efc08446162e555d0d6000df3f87900fd45ea
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.5
4
+ - 2.3.1
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ Version 2.3.0 (July 17, 2017)
5
+ -----------------------------
6
+
7
+ * Allow host-regex option
8
+
4
9
  Version 2.2.0 (August 11, 2016)
5
10
  -----------------------------
6
11
 
data/README.md CHANGED
@@ -1,23 +1,20 @@
1
- ## rack-www
1
+ [![Build Status](https://travis-ci.org/stjhimy/rack-www.svg?branch=master)](https://travis-ci.org/stjhimy/rack-www)
2
+
3
+ # rack-www
2
4
 
3
5
  Rack middleware to force subdomain redirects, e.g: www or www2
4
6
 
5
- ### Installation
7
+ ## Installation
6
8
 
7
9
  ```ruby
8
- #default installation
9
- gem install rack-www
10
-
11
- #when using bundler
12
10
  gem 'rack-www'
13
11
  ```
14
12
 
15
- ### Usage
13
+ ## Usage
16
14
 
17
- Default usage (by default will redirect all requests to www subdomain):
15
+ Usage (by default it will redirect all requests to www subdomain):
18
16
 
19
17
  ```ruby
20
- #redirects all traffic to www subdomain
21
18
  config.middleware.use Rack::WWW
22
19
  ```
23
20
 
@@ -35,7 +32,6 @@ Customizing the :www option to true or false:
35
32
  Redirecting to a given subdomain:
36
33
 
37
34
  ```ruby
38
- #redirects all traffic to the 'secure' subdomain
39
35
  config.middleware.use Rack::WWW, :subdomain => "secure"
40
36
  ```
41
37
 
@@ -53,15 +49,23 @@ You can optionally specify predicate to determine if redirect should take place:
53
49
  }
54
50
  ```
55
51
 
52
+ Specifying host-regex to determine on what hosts to redirect:
53
+
54
+ ```ruby
55
+ config.middleware.use Rack::WWW, :host_regex => /example/i
56
+ ```
57
+
58
+ This will only redirect when the host matches `example`, such as `example.com` or `example1.com`. It won't redirect on `localhost` or any other host that does not match the regex
59
+
56
60
  It ignores any redirects when using IP addresses.
57
61
 
58
- ### Options
62
+ ## Options
59
63
 
60
64
  - :www => default is true, redirects all traffic to www;
61
65
  - :subdomain => redirects to any given subdomain;
62
66
  - :message => display a message while redirecting;
67
+ - :host_regex => redirects if the given host match
63
68
 
69
+ ## License
64
70
 
65
- ### License
66
-
67
- MIT License. Copyright 2011 Jhimy Fernandes Villar http://stjhimy.com
71
+ MIT License. Copyright Jhimy Fernandes Villar http://stjhimy.com
@@ -12,6 +12,7 @@ module Rack
12
12
  @redirect = !@options[:www].nil? ? @options[:www] : true
13
13
  @message = @options[:message]
14
14
  @subdomain = @options[:subdomain]
15
+ @host_regex = @options[:host_regex] || /.+/i
15
16
  @predicate = @options[:predicate]
16
17
  end
17
18
 
@@ -38,7 +39,8 @@ module Rack
38
39
  end
39
40
 
40
41
  def redirect?(env)
41
- predicate?(env) && change_subdomain?(env) && !ip_request?(env)
42
+ predicate?(env) && change_subdomain?(env) && !ip_request?(env) &&
43
+ matches_host?(env)
42
44
  end
43
45
 
44
46
  def predicate?(env)
@@ -66,6 +68,10 @@ module Rack
66
68
  env['HTTP_HOST'].to_s.downcase =~ /^(#{@subdomain}\.)/
67
69
  end
68
70
 
71
+ def matches_host?(env)
72
+ env['HTTP_HOST'].to_s.downcase =~ @host_regex
73
+ end
74
+
69
75
  def prepare_url(env)
70
76
  scheme = env['rack.url_scheme']
71
77
  host, port, path, query_string = extract_host(env)
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rack-www'
3
- s.version = '2.2.0'
4
- s.date = '2015-12-02'
3
+ s.version = '2.3.0'
5
4
  s.homepage = 'https://github.com/stjhimy/rack-www'
6
5
  s.email = 'stjhimy@gmail.com'
7
6
  s.summary = 'Force redirects to a any given subdomain.'
@@ -14,7 +13,7 @@ Gem::Specification.new do |s|
14
13
  s.require_paths = ['lib']
15
14
  s.required_ruby_version = '>= 1.9.3'
16
15
 
17
- s.add_runtime_dependency 'rack', '~> 1.0'
16
+ s.add_runtime_dependency 'rack', '< 3.0'
18
17
  s.add_development_dependency 'rake', '~> 10.4'
19
18
  s.add_development_dependency 'rack-test', '~> 0.6'
20
19
  s.add_development_dependency 'minitest', '~> 5.8'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-www
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jhimy Fernandes Villar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-02 00:00:00.000000000 Z
11
+ date: 2017-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -115,8 +115,7 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - ".gitignore"
118
- - ".ruby-gemset"
119
- - ".ruby-version"
118
+ - ".travis.yml"
120
119
  - CHANGELOG.md
121
120
  - Gemfile
122
121
  - Guardfile
@@ -151,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
150
  version: '0'
152
151
  requirements: []
153
152
  rubyforge_project:
154
- rubygems_version: 2.4.5.1
153
+ rubygems_version: 2.5.1
155
154
  signing_key:
156
155
  specification_version: 4
157
156
  summary: Force redirects to a any given subdomain.
@@ -1 +0,0 @@
1
- rack-www
@@ -1 +0,0 @@
1
- 2.2.3