You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by tc...@redhat.com on 2011/01/18 20:32:00 UTC

[PATCH] Fixed url generation when deltacloud is behind a proxy or load balancer.

From: Tobias Crawley <tc...@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


Re: [PATCH] Fixed url generation when deltacloud is behind a proxy or load balancer.

Posted by David Lutterkort <lu...@redhat.com>.
On Tue, 2011-01-18 at 14:32 -0500, tcrawley@redhat.com wrote:
> From: Tobias Crawley <tc...@redhat.com>
> 
> The url_for helper wasn't properly honoring the scheme and port
> forwarded from a frontend load balancer or proxy.

ACK. Pushed.

David