rack-host-redirect 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92b5b6010274a1683c3f022f3bc5eec0668d5a0d
4
+ data.tar.gz: e07023e04de9ceff20e9b2562ba0d1f479b96999
5
+ SHA512:
6
+ metadata.gz: b15052b3c1405620291e7edf76afe70afa3fa327452696aa20fe74fad29930368fb8345f3a52a80a43ed38fa17aee9ae29839a88572c87e41b7b3cb0fc003bc0
7
+ data.tar.gz: 012d73abf8c756f64e894f03b8a28931d80106ecae820db7184cbc4665438e9592bca4484d5fdd63a18d4c2ec7a72ade172ecb61398c599abf60698906988f23
@@ -0,0 +1 @@
1
+ require 'rack/host_redirect'
@@ -0,0 +1,35 @@
1
+ require 'rack'
2
+ require 'uri'
3
+
4
+ class Rack::HostRedirect
5
+
6
+ def initialize(app, host_mapping = nil, &block)
7
+ @app = app
8
+ @host_mapping = downcase_keys(host_mapping) if host_mapping
9
+ @block = block
10
+ end
11
+
12
+ def call(env)
13
+ host = (env['HTTP_HOST'] || env['SERVER_NAME']).downcase
14
+ updated_host = (@host_mapping && @host_mapping[host]) || (@block && @block.call(host, env))
15
+
16
+ if updated_host
17
+ redirect_to(updated_host, env)
18
+ else
19
+ @app.call(env)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def downcase_keys hsh
26
+ hsh.inject({}) {|out, (k, v)| out[k.downcase] = v; out }
27
+ end
28
+
29
+ def redirect_to updated_host, env
30
+ request = Rack::Request.new(env)
31
+ location = URI.parse(request.url)
32
+ location.host = updated_host
33
+ [301, {'Location' => location.to_s}, []]
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-host-redirect
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Buesing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email: gbuesing@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/rack-host-redirect.rb
48
+ - lib/rack/host_redirect.rb
49
+ homepage: https://github.com/gbuesing/rack-host-redirect
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.0.0
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Lean and simple host redirection via Rack middleware
73
+ test_files: []