incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Lutterkort <lut...@redhat.com>
Subject Re: [PATCH] Fix for DTACLOUD-38: Bad URI's are reported when server started with -r 0.0.0.0
Date Wed, 28 Sep 2011 22:39:17 GMT
On Wed, 2011-09-28 at 15:31 -0400, Davanum Srinivas wrote:
> ---
>  server/lib/sinatra/url_for.rb |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/server/lib/sinatra/url_for.rb b/server/lib/sinatra/url_for.rb
> index 19a4fc7..707c64a 100644
> --- a/server/lib/sinatra/url_for.rb
> +++ b/server/lib/sinatra/url_for.rb
> @@ -67,7 +67,7 @@ module Sinatra
>          else
>            port = ":#{port}"
>          end
> -        request_host = HOSTNAME ? HOSTNAME : request.host
> +        request_host = (HOSTNAME && HOSTNAME!="0.0.0.0") ? HOSTNAME : request.host

Why don't we always use request.host ? Shouldn't that be the right thing
no matter what, now that we require a Host header ?

I ran into trouble running DC behind a reverse proxy; generated URL's
were all over the place. My tentative patch for addressing this (which
also uses request.host always) is:

>From 9fd3b40714a35ec5bf091ec01fff87f87304e4d5 Mon Sep 17 00:00:00 2001
From: David Lutterkort <lutter@redhat.com>
Date: Thu, 8 Sep 2011 17:31:01 -0400
Subject: [PATCH] url_for: make work with proxy


Signed-off-by: David Lutterkort <lutter@redhat.com>
---
 server/lib/sinatra/url_for.rb |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/server/lib/sinatra/url_for.rb b/server/lib/sinatra/url_for.rb
index 19a4fc7..2891a53 100644
--- a/server/lib/sinatra/url_for.rb
+++ b/server/lib/sinatra/url_for.rb
@@ -59,15 +59,21 @@ module Sinatra
       when :path_only
         base = request.script_name
       when :full
-        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 = request.scheme
+        port = request.port
+        request_host = request.host
+        if request.env['HTTP_X_FORWARDED_FOR']
+          scheme = request.env['HTTP_X_FORWARDED_SCHEME'] || scheme
+          port = request.env['HTTP_X_FORWARDED_PORT']
+          request_host = request.env['HTTP_X_FORWARDED_HOST']
+        end
+        if (port.nil? || port == "" ||
+            (scheme == 'http' && port.to_s == '80') ||
             (scheme == 'https' && port.to_s == '443'))
           port = ""
         else
           port = ":#{port}"
         end
-        request_host = HOSTNAME ? HOSTNAME : request.host
         base = "#{scheme}://#{request_host}#{port}#{request.script_name}"
       else
         raise TypeError, "Unknown url_for mode #{mode}"
-- 
1.7.6





Mime
View raw message