deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcraw...@redhat.com
Subject [PATCH] Fixed url generation when deltacloud is behind a proxy or load balancer.
Date Tue, 18 Jan 2011 19:32:00 GMT
From: Tobias Crawley <tcrawley@redhat.com>

The url_for helper wasn't properly honoring the scheme and port
forwarded from a frontend load balancer or proxy.

---
 server/lib/sinatra/url_for.rb |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/lib/sinatra/url_for.rb b/server/lib/sinatra/url_for.rb
index ce95567..08e8a1a 100644
--- a/server/lib/sinatra/url_for.rb
+++ b/server/lib/sinatra/url_for.rb
@@ -20,12 +20,13 @@ module Sinatra
       when :path_only
         base = request.script_name
       when :full
-        scheme = request.scheme
-        if (scheme == 'http' && request.port == 80 ||
-            scheme == 'https' && request.port == 443)
+        scheme = request.env['HTTP_X_FORWARDED_SCHEME'] || request.scheme
+        port = request.env['HTTP_X_FORWARDED_PORT'] || request.port
+        if ((scheme == 'http' && port.to_s == '80') ||
+            (scheme == 'https' && port.to_s == '443'))
           port = ""
         else
-          port = ":#{request.port}"
+          port = ":#{port}"
         end
         request_host = HOSTNAME ? HOSTNAME : request.host
         base = "#{scheme}://#{request_host}#{port}#{request.script_name}"
-- 
1.7.3.2


Mime
View raw message