Commits

Anonymous committed e5fb3ba

change the way to het Hostname, We try first to see if we are behind a
proxy by default we test if X-Forwarded-Host is in the headers (default
for apache and some others proxy), proxy host header could also be
configured in x_forwared_host application environnement variable. If we
aren't behind a proxy we get Host header. If undefined we return
no_host_provided and we will match '*' .

Comments (0)

Files changed (2)

src/webmachine_dispatcher.erl

                     dispatch1(HostNameParts1, DispatchList, Path, ExtraDepth, HostDepth-1)
             end;
         {DispatchList1, Bindings} ->
+            io:format("bindings ~p ~n", [Bindings]),
             case try_binding(lists:reverse(DispatchList1), Path, ExtraDepth) of
                 {no_dispatch_match, _UnmatchedPathTokens} ->
                     case try_binding(DispatchList, Path, ExtraDepth) of

src/webmachine_mochiweb.erl

 
 
 host(MochiReq) ->
-	case MochiReq:get_header_value("Host") of
+    XHost = case application:get_env(x_forwarded_host) of
+        undefined -> "X-Forwarded-Host";
+        {ok, Value} -> Value
+    end,
+    io:format("host ~p ~n", [XHost]),
+    case MochiReq:get_header_value(XHost) of
         undefined ->
-            {ok, {Address, Port}} = inet:sockname(MochiReq:get(socket)),
-            inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port);
-        Value -> Value
+	        case MochiReq:get_header_value("Host") of
+                undefined -> no_host_provided;
+                Val1 -> Val1
+            end;
+        Val -> Val
     end.