hostrich 0.3.0 → 0.4.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.rb +6 -2
- data/lib/hostrich/version.rb +1 -1
- data/spec/hostrich_spec.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a25bc0af04ff0238dd11a60112e8f44fe1933d8
|
4
|
+
data.tar.gz: 489d989a2b9fe326164531c3b8dc3220f770ec14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b51f6a826f8097c8e21ec924c18b8c3bc38d6cfee0ffbb5c911dcfd4b52b2d910c08584839ce260869230e4e63e3a39ae9bfe114d74e6238af7e439eef3a4c10
|
7
|
+
data.tar.gz: 41dd2c6923e897606db5c521bfb0d4d9b90a678e4e667ae108a57c2e6d83615948fb5b8e95322df565f5bfdb738de165f40889a190107a93977810a6a66e6a36
|
data/lib/hostrich.rb
CHANGED
@@ -32,11 +32,15 @@ class Hostrich
|
|
32
32
|
|
33
33
|
suffix = match[1]
|
34
34
|
|
35
|
-
# Fake request
|
35
|
+
# Fake host in request headers.
|
36
36
|
# Eg. If request is made from http://example.com.dev or http://example.com.127.0.0.1.xip.io,
|
37
37
|
# the Rack app will see it just as a request to http://example.com.
|
38
|
-
env['HTTP_HOST'] = remove_suffix(env['HTTP_HOST'], suffix)
|
39
38
|
env['SERVER_NAME'] = remove_suffix(env['SERVER_NAME'], suffix)
|
39
|
+
env.each do |key, value|
|
40
|
+
if key.start_with?('HTTP_') && String === value
|
41
|
+
env[key] = remove_suffix(value, suffix)
|
42
|
+
end
|
43
|
+
end
|
40
44
|
|
41
45
|
# Get regular response from Rack app
|
42
46
|
status, headers, body = @app.call(env)
|
data/lib/hostrich/version.rb
CHANGED
data/spec/hostrich_spec.rb
CHANGED
@@ -9,6 +9,10 @@ describe Hostrich do
|
|
9
9
|
case env['PATH_INFO']
|
10
10
|
when '/redirect'
|
11
11
|
[302, { 'Location' => 'http://foo.com/index.html' }, []]
|
12
|
+
when '/origin'
|
13
|
+
[200, {}, [env['HTTP_ORIGIN'] == 'http://foo.com' ? 'right' : 'wrong']]
|
14
|
+
when '/referer'
|
15
|
+
[200, {}, [env['HTTP_REFERER'] == 'http://foo.com' ? 'right' : 'wrong']]
|
12
16
|
when '/cookie'
|
13
17
|
[200, { 'Set-Cookie' => 'some_param=foo.com/index.html; Path=/; Domain=.foo.bar.io' }, ['Cookie!']]
|
14
18
|
when '/version.rb'
|
@@ -27,6 +31,12 @@ describe Hostrich do
|
|
27
31
|
|
28
32
|
response = request.get('/cookie', 'HTTP_HOST' => 'foo.com.dev')
|
29
33
|
expect(response.headers['Set-Cookie']).to eq 'some_param=foo.com.dev/index.html; Path=/; Domain=.foo.bar.io'
|
34
|
+
|
35
|
+
response = request.get('/origin', 'HTTP_HOST' => 'foo.com.dev', 'HTTP_ORIGIN' => 'http://foo.com.dev')
|
36
|
+
expect(response.body).to eq 'right'
|
37
|
+
|
38
|
+
response = request.get('/referer', 'HTTP_HOST' => 'foo.com.dev', 'HTTP_REFERER' => 'http://foo.com.dev')
|
39
|
+
expect(response.body).to eq 'right'
|
30
40
|
end
|
31
41
|
|
32
42
|
it 'works with Rack::File' do
|
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.4.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:
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.2
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Hostrich is a Rack middleware that eases multi-domain web app development.
|