shuber-proxy 1.3.1 → 1.3.2

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.
Files changed (5) hide show
  1. data/CHANGELOG +5 -0
  2. data/README.markdown +2 -2
  3. data/lib/proxy.rb +5 -1
  4. data/test/init.rb +103 -0
  5. metadata +3 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 2009-06-05 - Sean Huber (shuber@huberry.com)
2
+ * Add multiple domain support for rack
3
+ * Update gemspec
4
+ * Update README
5
+
1
6
  2009-06-04 - Sean Huber (shuber@huberry.com)
2
7
  * Update test related rake tasks
3
8
  * Remove huberry namespace
@@ -4,7 +4,7 @@ A gem/plugin that allows rails applications to dynamically respond to multiple d
4
4
 
5
5
  The original session domain, default host, and relative url root will be restored after each request.
6
6
 
7
- Requires actionpack version >= 2.0.0
7
+ Requires actionpack >= 2.0.0
8
8
 
9
9
 
10
10
  ## Installation
@@ -73,7 +73,7 @@ Now, it gets tricky if you want `http://cool-site.com` to render `cool-site`'s p
73
73
 
74
74
  # you can put this in an initializer or something instead if you'd like
75
75
  Proxy.replace_host_with do |request|
76
- "#{Site.find_by_domain(request.host).try(:subdomain) || '-INVALID-'}.yourcmsapp.com" unless request.host =~ /(.*\.|^)yourcmsapp.com$/i
76
+ "#{Site.find_by_domain(request.host).try(:subdomain) || '-INVALID-'}.yourcmsapp.com" unless request.host =~ /(\.|^)yourcmsapp.com$/i
77
77
  end
78
78
 
79
79
  end
@@ -15,7 +15,11 @@ module Proxy
15
15
  private
16
16
 
17
17
  def self.before_dispatch(dispatcher)
18
- request = dispatcher.instance_variable_get('@request')
18
+ request = dispatcher.instance_variable_get('@request') || dispatcher.instance_variable_get('@env')
19
+ if request.is_a?(Hash)
20
+ request.each(&:inspect) # TODO: we can't access the 'rack.request' key without doing this first...wtf
21
+ request = request['rack.request']
22
+ end
19
23
  new_host = replace_host_with_proc.call(request)
20
24
  request.env['HTTP_X_FORWARDED_HOST'] = [request.host, new_host].join(', ') unless new_host.blank?
21
25
  end
@@ -0,0 +1,103 @@
1
+ $:.reject! { |path| path.include? 'TextMate' }
2
+ require 'test/unit'
3
+
4
+ # Load rubygems
5
+ #
6
+ require 'rubygems'
7
+
8
+ # Load ActionPack
9
+ #
10
+ args = ['actionpack']
11
+ args << ENV['ACTION_PACK_VERSION'] if ENV['ACTION_PACK_VERSION']
12
+ gem *args
13
+ require 'action_pack'
14
+ require 'action_controller'
15
+ require 'action_controller/dispatcher'
16
+ require 'action_controller/routing'
17
+ require 'action_controller/session_management'
18
+ require 'action_controller/url_rewriter'
19
+ require 'action_controller/test_process'
20
+ require 'action_view'
21
+
22
+ Test::Unit::TestCase.class_eval do
23
+ include ActionController::TestProcess
24
+
25
+ unless instance_methods.include?('assert_redirected_to')
26
+ def assert_redirected_to(url)
27
+ assert @response.redirect?
28
+ assert_equal url, @response.location
29
+ end
30
+ end
31
+ end
32
+
33
+ # Routing
34
+ #
35
+ class ActionController::Routing::RouteSet
36
+ def append
37
+ yield Mapper.new(self)
38
+ install_helpers
39
+ end
40
+ end
41
+
42
+ ActionController::Base.session_options.merge! :key => '_proxy_session', :secret => '60447f093cd3f5d57686dd5ca1ced83216c846047db0ec97480a5e85411d9bd41ec5587cc4aafac27a4f0e649f0c628b0955b315856b78787a96168671dc96d4'
43
+
44
+ # Require the main proxy.rb file
45
+ #
46
+ require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'proxy')
47
+
48
+ # Test controller
49
+ #
50
+ class TestController < ActionController::Base
51
+
52
+ def asset_action
53
+ render :inline => '<%= image_tag "test.gif" %>, <%= javascript_include_tag "test" %>, <%= stylesheet_link_tag "test" %>'
54
+ end
55
+
56
+ def exception_action
57
+ raise 'Uh oh'
58
+ end
59
+
60
+ def named_route_action
61
+ render :text => normal_action_url
62
+ end
63
+
64
+ def normal_action
65
+ render :text => url_for(:controller => 'test', :action => 'normal_action')
66
+ end
67
+
68
+ def redirect_action
69
+ redirect_to :action => 'normal_action'
70
+ end
71
+
72
+ def redirect_with_named_route_action
73
+ redirect_to normal_action_path
74
+ end
75
+
76
+ def session_action
77
+ render :text => ActionController::Base.session_options[:session_domain]
78
+ end
79
+
80
+ def view_action
81
+ render :inline => '<%= normal_action_path %>, <%= normal_action_url %>, <%= url_for(:controller => "test", :action => "normal_action") %>, <%= url_for(:controller => "test", :action => "normal_action", :only_path => true) %>'
82
+ end
83
+
84
+ protected
85
+
86
+ def rescue_action(e)
87
+ raise e
88
+ end
89
+ end
90
+
91
+ # Test routes
92
+ #
93
+ ActionController::Routing::Routes.append do |map|
94
+ map.connect 'asset_action', :controller => 'test', :action => 'asset_action'
95
+ map.connect 'exception_action', :controller => 'test', :action => 'exception_action'
96
+ map.connect 'named_route_action', :controller => 'test', :action => 'named_route_action'
97
+ map.connect 'normal_action', :controller => 'test', :action => 'normal_action'
98
+ map.connect 'redirect_action', :controller => 'test', :action => 'redirect_action'
99
+ map.connect 'redirect_with_named_route_action', :controller => 'test', :action => 'redirect_with_named_route_action'
100
+ map.connect 'session_action', :controller => 'test', :action => 'session_action'
101
+ map.connect 'view_action', :controller => 'test', :action => 'view_action'
102
+ map.normal_action 'normal_action', :controller => 'test', :action => 'normal_action'
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuber-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-04 00:00:00 -07:00
12
+ date: 2009-06-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,7 @@ files:
33
33
  - MIT-LICENSE
34
34
  - Rakefile
35
35
  - README.markdown
36
+ - test/init.rb
36
37
  has_rdoc: false
37
38
  homepage: http://github.com/shuber/proxy
38
39
  post_install_message: