hostrich 0.3.0 → 0.4.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: 87645430ed5a8510784bfb5faf7ec6d484eefeee
4
- data.tar.gz: 491fba7c08cd85e0dca1c853b9beeff24ff28e70
3
+ metadata.gz: 6a25bc0af04ff0238dd11a60112e8f44fe1933d8
4
+ data.tar.gz: 489d989a2b9fe326164531c3b8dc3220f770ec14
5
5
  SHA512:
6
- metadata.gz: 1e28112181156877df78b420a3a6da154c6112863b5b2bba6f9845815eb7a9abf09b07ae4955d4e15ebeb9db86e1f1b0db8e61ea4fa6550a4e39cb4fd519ebac
7
- data.tar.gz: 795a8bd7a1d1bf2f25a4010ca1ebe7421fc609cb0bfb3533650c26c402d551415a2047cdca64d6666969a7f2d2c4378c60993961d1ea9702dc75f628a4db0d44
6
+ metadata.gz: b51f6a826f8097c8e21ec924c18b8c3bc38d6cfee0ffbb5c911dcfd4b52b2d910c08584839ce260869230e4e63e3a39ae9bfe114d74e6238af7e439eef3a4c10
7
+ data.tar.gz: 41dd2c6923e897606db5c521bfb0d4d9b90a678e4e667ae108a57c2e6d83615948fb5b8e95322df565f5bfdb738de165f40889a190107a93977810a6a66e6a36
@@ -32,11 +32,15 @@ class Hostrich
32
32
 
33
33
  suffix = match[1]
34
34
 
35
- # Fake request host.
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)
@@ -1,3 +1,3 @@
1
1
  class Hostrich
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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.3.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: 2015-03-17 00:00:00.000000000 Z
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.4.5
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.