From ac538590984a66c73dd80dec169236798f7181d7 Mon Sep 17 00:00:00 2001 From: Sean Huber Date: Mon, 29 Sep 2008 10:26:52 -0700 Subject: [PATCH] Initial import --- .gitignore | 1 + CHANGELOG | 2 ++ MIT-LICENSE | 20 +++++++++++ README.markdown | 0 init.rb | 2 ++ lib/huberry/action_controller/base.rb | 39 +++++++++++++++++++++ lib/huberry/action_controller/dispatcher.rb | 14 ++++++++ lib/proxy.rb | 5 +++ test/base.rb | 4 +++ test/dispatcher_test.rb | 4 +++ test/init.rb | 29 +++++++++++++++ 11 files changed, 120 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG create mode 100644 MIT-LICENSE create mode 100644 README.markdown create mode 100644 init.rb create mode 100644 lib/huberry/action_controller/base.rb create mode 100644 lib/huberry/action_controller/dispatcher.rb create mode 100644 lib/proxy.rb create mode 100644 test/base.rb create mode 100644 test/dispatcher_test.rb create mode 100644 test/init.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..428a0ff --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,2 @@ +2008-09-29 - Sean Huber (shuber@huberry.com) + * Initial import \ No newline at end of file diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..b8028a9 --- /dev/null +++ b/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. \ No newline at end of file diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..e69de29 diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..8c9fb97 --- /dev/null +++ b/init.rb @@ -0,0 +1,2 @@ +require 'proxy' +$:.unshift File.join(File.dirname(__FILE__), 'lib') \ No newline at end of file diff --git a/lib/huberry/action_controller/base.rb b/lib/huberry/action_controller/base.rb new file mode 100644 index 0000000..a39fa4a --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/huberry/action_controller/dispatcher.rb b/lib/huberry/action_controller/dispatcher.rb new file mode 100644 index 0000000..d0de66e --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/proxy.rb b/lib/proxy.rb new file mode 100644 index 0000000..ef96d26 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/base.rb b/test/base.rb new file mode 100644 index 0000000..a4fb570 --- /dev/null +++ b/test/base.rb @@ -0,0 +1,4 @@ +require File.dirname(__FILE__) + '/init' + +class BaseTest < Test::Unit::TestCase +end \ No newline at end of file diff --git a/test/dispatcher_test.rb b/test/dispatcher_test.rb new file mode 100644 index 0000000..294327a --- /dev/null +++ b/test/dispatcher_test.rb @@ -0,0 +1,4 @@ +require File.dirname(__FILE__) + '/init' + +class DispatcherTest < Test::Unit::TestCase +end \ No newline at end of file diff --git a/test/init.rb b/test/init.rb new file mode 100644 index 0000000..44db15e --- /dev/null +++ b/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') \ No newline at end of file