From 0a902eb4ad64ee86f8af9915efb26a46bbb84d50 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Tue, 18 Aug 2009 17:09:42 +0000 Subject: allow configurable X-Forwarded-Host header handling for work behind reverse proxies, patch by Benoit Chesneau, closes COUCHDB-466 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@805500 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 2dc53b80..61bdc177 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -256,10 +256,16 @@ path(#httpd{mochi_req=MochiReq}) -> MochiReq:get(path). absolute_uri(#httpd{mochi_req=MochiReq}, Path) -> - Host = case MochiReq:get_header_value("Host") of + XHost = couch_config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"), + Host = case MochiReq:get_header_value(XHost) of undefined -> - {ok, {Address, Port}} = inet:sockname(MochiReq:get(socket)), - inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port); + case MochiReq:get_header_value("Host") of + undefined -> + {ok, {Address, Port}} = inet:sockname(MochiReq:get(socket)), + inet_parse:ntoa(Address) ++ ":" ++ integer_to_list(Port); + Value1 -> + Value1 + end; Value -> Value end, "http://" ++ Host ++ Path. -- cgit v1.2.3