hostrich 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hostrich/version.rb +1 -1
- data/lib/hostrich.rb +5 -1
- data/spec/hostrich_spec.rb +28 -16
- 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: 87645430ed5a8510784bfb5faf7ec6d484eefeee
|
4
|
+
data.tar.gz: 491fba7c08cd85e0dca1c853b9beeff24ff28e70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e28112181156877df78b420a3a6da154c6112863b5b2bba6f9845815eb7a9abf09b07ae4955d4e15ebeb9db86e1f1b0db8e61ea4fa6550a4e39cb4fd519ebac
|
7
|
+
data.tar.gz: 795a8bd7a1d1bf2f25a4010ca1ebe7421fc609cb0bfb3533650c26c402d551415a2047cdca64d6666969a7f2d2c4378c60993961d1ea9702dc75f628a4db0d44
|
data/lib/hostrich/version.rb
CHANGED
data/lib/hostrich.rb
CHANGED
@@ -23,7 +23,11 @@ class Hostrich
|
|
23
23
|
|
24
24
|
# Extract suffix from current request host.
|
25
25
|
match = nil
|
26
|
-
@@hosts.detect { |host|
|
26
|
+
@@hosts.detect { |host|
|
27
|
+
if http_host = env['HTTP_HOST']
|
28
|
+
match = http_host.match(/#{host}(\.[\.\w-]+)?/)
|
29
|
+
end
|
30
|
+
}
|
27
31
|
return @app.call(env) if match.nil?
|
28
32
|
|
29
33
|
suffix = match[1]
|
data/spec/hostrich_spec.rb
CHANGED
@@ -10,53 +10,65 @@ describe Hostrich do
|
|
10
10
|
when '/redirect'
|
11
11
|
[302, { 'Location' => 'http://foo.com/index.html' }, []]
|
12
12
|
when '/cookie'
|
13
|
-
[200, { 'Set-Cookie' => 'some_param=foo.com/index.html; Path=/; Domain=.foo.
|
13
|
+
[200, { 'Set-Cookie' => 'some_param=foo.com/index.html; Path=/; Domain=.foo.bar.io' }, ['Cookie!']]
|
14
14
|
when '/version.rb'
|
15
15
|
Rack::File.new('lib/hostrich').call(env)
|
16
16
|
else
|
17
|
-
[200, {}, ['Welcome to foo.com or foo.
|
17
|
+
[200, {}, ['Welcome to foo.com, foo.com.dev or foo.bar.io, not foo.comzle, not ffoo.com and not bar.io']]
|
18
18
|
end
|
19
19
|
}
|
20
20
|
}
|
21
21
|
let(:request) { Rack::MockRequest.new(stack) }
|
22
22
|
|
23
|
-
shared_examples '
|
24
|
-
it 'adds host suffix in response body' do
|
25
|
-
response = request.get('/', 'HTTP_HOST' => 'foo.com.dev')
|
26
|
-
expect(response.body).to eq 'Welcome to foo.com.dev or foo.com.dev, not foo.comzle, not ffoo.com and not bar.io'
|
27
|
-
end
|
28
|
-
|
23
|
+
shared_examples 'adds suffix to single host' do
|
29
24
|
it 'adds host suffix in response headers' do
|
30
25
|
response = request.get('/redirect', 'HTTP_HOST' => 'foo.com.dev')
|
31
26
|
expect(response.headers['Location']).to eq 'http://foo.com.dev/index.html'
|
32
27
|
|
33
28
|
response = request.get('/cookie', 'HTTP_HOST' => 'foo.com.dev')
|
34
|
-
expect(response.headers['Set-Cookie']).to eq 'some_param=foo.com.dev/index.html; Path=/; Domain=.foo.
|
29
|
+
expect(response.headers['Set-Cookie']).to eq 'some_param=foo.com.dev/index.html; Path=/; Domain=.foo.bar.io'
|
35
30
|
end
|
36
31
|
|
37
32
|
it 'works with Rack::File' do
|
38
33
|
response = request.get('/version.rb', 'HTTP_HOST' => 'foo.com.dev')
|
39
34
|
expect(response.body).to include "class Hostrich\n VERSION"
|
40
35
|
end
|
36
|
+
|
37
|
+
it 'adds host suffix in response body' do
|
38
|
+
response = request.get('/', 'HTTP_HOST' => 'foo.com.dev')
|
39
|
+
expect(response.body).to eq 'Welcome to foo.com.dev, foo.com.dev or foo.bar.io, not foo.comzle, not ffoo.com and not bar.io'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'processes request successfully if no HTTP_HOST present' do
|
43
|
+
response = request.get('/')
|
44
|
+
expect(response.body).to eq 'Welcome to foo.com, foo.com.dev or foo.bar.io, not foo.comzle, not ffoo.com and not bar.io'
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
context 'passing host as a string' do
|
44
49
|
let(:stack) { Hostrich.new(app, 'foo.com') }
|
45
|
-
|
50
|
+
include_examples 'adds suffix to single host'
|
46
51
|
end
|
47
52
|
|
48
53
|
context 'passing host as an array' do
|
49
54
|
let(:stack) { Hostrich.new(app, ['foo.com']) }
|
50
|
-
|
55
|
+
include_examples 'adds suffix to single host'
|
51
56
|
end
|
52
57
|
|
53
58
|
context 'passing multiple hosts as an array' do
|
54
59
|
let(:stack) { Hostrich.new(app, %w[foo.com foo.bar.io]) }
|
55
|
-
it_behaves_like 'the whole deal'
|
56
60
|
|
57
|
-
it 'adds host suffix
|
61
|
+
it 'adds host suffix to multiple hosts in response headers' do
|
62
|
+
response = request.get('/redirect', 'HTTP_HOST' => 'foo.com.dev')
|
63
|
+
expect(response.headers['Location']).to eq 'http://foo.com.dev/index.html'
|
64
|
+
|
65
|
+
response = request.get('/cookie', 'HTTP_HOST' => 'foo.com.dev')
|
66
|
+
expect(response.headers['Set-Cookie']).to eq 'some_param=foo.com.dev/index.html; Path=/; Domain=.foo.bar.io.dev'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'adds host suffix to multiple hosts in response body' do
|
58
70
|
response = request.get('/', 'HTTP_HOST' => 'foo.com.127.0.0.1.xip.io')
|
59
|
-
expect(response.body).to eq 'Welcome to foo.com.127.0.0.1.xip.io
|
71
|
+
expect(response.body).to eq 'Welcome to foo.com.127.0.0.1.xip.io, foo.com.127.0.0.1.xip.io.dev or foo.bar.io.127.0.0.1.xip.io, not foo.comzle, not ffoo.com and not bar.io'
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
@@ -65,12 +77,12 @@ describe Hostrich do
|
|
65
77
|
|
66
78
|
it 'does nothing' do
|
67
79
|
response = request.get('/', 'HTTP_HOST' => 'foo.com.dev')
|
68
|
-
expect(response.body).to eq 'Welcome to foo.com or foo.
|
80
|
+
expect(response.body).to eq 'Welcome to foo.com, foo.com.dev or foo.bar.io, not foo.comzle, not ffoo.com and not bar.io'
|
69
81
|
end
|
70
82
|
|
71
83
|
context 'adding hosts after initialization' do
|
72
84
|
before { Hostrich.hosts += ['foo.com'] }
|
73
|
-
|
85
|
+
include_examples 'adds suffix to single host'
|
74
86
|
end
|
75
87
|
end
|
76
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hostrich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafaël Blais Masson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|