Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
shuber committed Sep 29, 2008
0 parents commit ac53859
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.DS_Store
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -0,0 +1,2 @@
2008-09-29 - Sean Huber (shuber@huberry.com)
* Initial import
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 Sean Huber (shuber@huberry.com)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added README.markdown
Empty file.
2 changes: 2 additions & 0 deletions init.rb
@@ -0,0 +1,2 @@
require 'proxy'
$:.unshift File.join(File.dirname(__FILE__), 'lib')
39 changes: 39 additions & 0 deletions lib/huberry/action_controller/base.rb
@@ -0,0 +1,39 @@
module Huberry
module ActionController
module Base
def self.included(base)
base.class_eval do
cattr_accessor :relative_url_root
alias_method_chain :redirect_to, :forwarded_host
around_filter :set_relative_url_root
end
end

def redirect_to_with_forwarded_host(options = {}, response_status = {})
unless request.env['HTTP_X_FORWARDED_HOST'].blank?
host = request.env['HTTP_X_FORWARDED_HOST'].split(', ').first
if options.is_a? Hash
options[:host] = host
else
request.instance_variable_set('@host_with_port', host + request.port_string)
end
end
redirect_to_without_forwarded_host(options, response_status)
end

def set_relative_url_root
if self.class.relative_url_root.blank?
yield
else
@original_relative_url_root = ActionController::AbstractRequest.relative_url_root.to_s
ActionController::AbstractRequest.relative_url_root = self.class.relative_url_root
begin
yield
ensure
ActionController::AbstractRequest.relative_url_root = @original_relative_url_root
end
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/huberry/action_controller/dispatcher.rb
@@ -0,0 +1,14 @@
module Huberry
module ActionController
module Dispatcher
def self.included(base)
base.send :before_dispatch, :set_session_domain
end

def set_session_domain
host = @request.env['HTTP_X_FORWARDED_HOST'].blank? ? @request.host : @request.env['HTTP_X_FORWARDED_HOST'].split(', ').first
ApplicationController.session_options.merge!(:session_domain => ".#{$1}") if /([^\.]+\.[^\.]+)$/.match(host)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/proxy.rb
@@ -0,0 +1,5 @@
require 'huberry/action_controller/dispatcher'
require 'huberry/action_controller/base'

::ActionController::Dispatcher.send :include, ::Huberry::ActionController::Dispatcher
::ActionController::Base.send :include, ::Huberry::ActionController::Base
4 changes: 4 additions & 0 deletions test/base.rb
@@ -0,0 +1,4 @@
require File.dirname(__FILE__) + '/init'

class BaseTest < Test::Unit::TestCase
end
4 changes: 4 additions & 0 deletions test/dispatcher_test.rb
@@ -0,0 +1,4 @@
require File.dirname(__FILE__) + '/init'

class DispatcherTest < Test::Unit::TestCase
end
29 changes: 29 additions & 0 deletions test/init.rb
@@ -0,0 +1,29 @@
$:.reject! { |path| path.include? 'TextMate' }
require 'test/unit'

# Load rubygems
#
require 'rubygems'

# Load ActionPack
#
gem 'actionpack'
require 'action_pack'
require 'action_controller'
require 'action_controller/dispatcher'
require 'action_controller/routing'
require 'action_controller/assertions'
require 'action_controller/test_process'

# Routing
#
class ActionController::Routing::RouteSet
def append
yield Mapper.new(self)
install_helpers
end
end

# Require the main proxy.rb file
#
require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'proxy')

0 comments on commit ac53859

Please sign in to comment.