From df78e9c40e44334468f91d1779905652eb8b2114 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Thu, 25 Jul 2013 15:11:23 +0100 Subject: [PATCH 1/3] Don't use 'rescue' unecessarily Throwing exceptions & catching them is relatively slow - we can make url_for measurably faster by avoiding that --- lib/ssl_requirement.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ssl_requirement.rb b/lib/ssl_requirement.rb index aaa08e8..203e5c7 100644 --- a/lib/ssl_requirement.rb +++ b/lib/ssl_requirement.rb @@ -28,8 +28,11 @@ module SslRequirement :disable_ssl_check mattr_accessor :redirect_status + self.ssl_host = nil + self.non_ssl_host = nil + def self.ssl_host - determine_host(@@ssl_host) rescue nil + determine_host(@@ssl_host) end def self.ssl_port @@ -37,7 +40,7 @@ def self.ssl_port end def self.non_ssl_host - determine_host(@@non_ssl_host) rescue nil + determine_host(@@non_ssl_host) end def self.non_ssl_port From 7f1aecc9ace23975031259bb91db59dcdb29cc54 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Sat, 3 Jan 2015 17:46:26 +0000 Subject: [PATCH 2/3] Replace .rvmrc with .ruby-version & .ruby-gemset --- .ruby-gemset | 1 + .ruby-version | 1 + .rvmrc | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .ruby-gemset create mode 100644 .ruby-version delete mode 100644 .rvmrc diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..8bb43a1 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +ssl_requirement diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..5dcf256 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-1.9.3-p0 diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index be7c18d..0000000 --- a/.rvmrc +++ /dev/null @@ -1 +0,0 @@ -rvm use ruby-1.9.3-p0@ssl_requirement --create From 5f2f2e21503016a7001c02d73bc9c98d7f26d67f Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Sat, 3 Jan 2015 17:48:13 +0000 Subject: [PATCH 3/3] Fix url_for signature for Rails 4.2 --- lib/url_for.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/url_for.rb b/lib/url_for.rb index 3d8d3bf..11f264b 100644 --- a/lib/url_for.rb +++ b/lib/url_for.rb @@ -6,7 +6,7 @@ module Routing class RouteSet # Add a secure option to the rewrite method. - def url_for_with_secure_option(options = {}) + def url_for_with_secure_option(options = {}, route_name = nil, url_strategy = UNKNOWN) secure = options.delete(:secure) # if secure && ssl check is not disabled, convert to full url with https @@ -30,18 +30,18 @@ def url_for_with_secure_option(options = {}) end end - url_for_without_secure_option(options) + url_for_without_secure_option(options, route_name, url_strategy) end # if full URL is requested for http and we've been told to use a # non-ssl host override, then use it - def url_for_with_non_ssl_host(options) + def url_for_with_non_ssl_host(options, route_name = nil, url_strategy = UNKNOWN) if !options[:only_path] && !SslRequirement.non_ssl_host.nil? if !(/^https/ =~ (options[:protocol] || @request.try(:protocol))) options.merge! :host => SslRequirement.non_ssl_host end end - url_for_without_non_ssl_host(options) + url_for_without_non_ssl_host(options, route_name, url_strategy) end # want with_secure_option to get run first (so chain it last)