couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [02/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372
Date Tue, 01 Mar 2016 20:00:35 GMT
Extract host_for_request/1 as it is done in original


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/9b3b8b5a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/9b3b8b5a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/9b3b8b5a

Branch: refs/heads/split_out_httpd_stack
Commit: 9b3b8b5a0248272958f840ee577375f18a603a3f
Parents: 3291f97
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Feb 25 10:55:02 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 1 08:35:06 2016 -0800

----------------------------------------------------------------------
 src/couch_httpd.erl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/9b3b8b5a/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index d8786d1..c268f8c 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -390,19 +390,25 @@ validate_ctype(Req, Ctype) ->
         end
     end.
 
-absolute_uri(#httpd{mochi_req=MochiReq, absolute_uri = undefined}, Path) ->
+host_for_request(#httpd{mochi_req = MochiReq}) ->
     XHost = config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
-    Host = case MochiReq:get_header_value(XHost) of
+    case MochiReq:get_header_value(XHost) of
         undefined ->
             case MochiReq:get_header_value("Host") of
                 undefined ->
-                    {ok, {Address, Port}} = inet:sockname(MochiReq:get(socket)),
+                    {ok, {Address, Port}} = case MochiReq:get(socket) of
+                        {ssl, SslSocket} -> ssl:sockname(SslSocket);
+                        Socket -> inet:sockname(Socket)
+                    end,
                     inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port);
                 Value1 ->
                     Value1
             end;
         Value -> Value
-    end,
+    end.
+
+absolute_uri(#httpd{mochi_req=MochiReq, absolute_uri = undefined} = Req, Path) ->
+    Host = host_for_request(Req),
     XSsl = config:get("httpd", "x_forwarded_ssl", "X-Forwarded-Ssl"),
     Scheme = case MochiReq:get_header_value(XSsl) of
         "on" -> "https";


Mime
View raw message