summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chttpd.erl11
-rw-r--r--src/chttpd_db.erl10
-rw-r--r--src/chttpd_external.erl10
-rw-r--r--src/chttpd_misc.erl3
4 files changed, 11 insertions, 23 deletions
diff --git a/src/chttpd.erl b/src/chttpd.erl
index daf9b4da..1cc15d7e 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -63,9 +63,7 @@ handle_request(MochiReq) ->
% for the path, use the raw path with the query string and fragment
% removed, but URL quoting left intact
RawUri = MochiReq:get(raw_path),
- Customer = cloudant_util:customer_name(
- MochiReq:get_header_value("X-Cloudant-User"),
- MochiReq:get_header_value("Host")),
+ Customer = cloudant_util:customer_name(#httpd{mochi_req=MochiReq}),
Path = ?COUCH:db_path(RawUri, Customer),
{HandlerKey, _, _} = mochiweb_util:partition(Path, "/"),
@@ -245,7 +243,7 @@ qs(#httpd{mochi_req=MochiReq}) ->
path(#httpd{mochi_req=MochiReq}) ->
MochiReq:get(path).
-absolute_uri(#httpd{mochi_req=MochiReq}, Path) ->
+absolute_uri(#httpd{mochi_req=MochiReq} = Req, Path) ->
XHost = couch_config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
Host = case MochiReq:get_header_value(XHost) of
undefined ->
@@ -270,10 +268,7 @@ absolute_uri(#httpd{mochi_req=MochiReq}, Path) ->
_ -> "http"
end
end,
- Customer = cloudant_util:customer_name(
- MochiReq:get_header_value("X-Cloudant-User"),
- Host),
- CustomerRegex = ["^/", Customer, "[/%2F]+"],
+ CustomerRegex = ["^/", cloudant_util:customer_name(Req), "[/%2F]+"],
NewPath = re:replace(Path, CustomerRegex, "/"),
Scheme ++ "://" ++ Host ++ NewPath.
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 94a43e20..1ae5629d 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -165,10 +165,8 @@ do_db_req(#httpd{path_parts=[DbName|_]}=Req, Fun) ->
Fun(Req, #db{name=DbName}).
db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) ->
- Customer = cloudant_util:customer_name(chttpd:header_value(Req, "X-Cloudant-User"),
- chttpd:header_value(Req, "Host")),
- {ok, DbInfo} = ?COUCH:get_db_info(DbName, Customer),
- send_json(Req, {DbInfo});
+ {ok, DbInfo} = fabric:get_db_info(DbName),
+ send_json(Req, {cloudant_util:customer_db_info(Req, DbInfo)});
db_req(#httpd{method='POST',path_parts=[DbName]}=Req, Db) ->
Doc = couch_doc:from_json_obj(chttpd:json_body(Req)),
@@ -332,9 +330,7 @@ db_req(#httpd{method='GET',path_parts=[_,<<"_all_docs_by_seq">>]}=Req, Db) ->
direction = Dir
} = QueryArgs = chttpd_view:parse_view_params(Req, nil, map),
- Customer = cloudant_util:customer_name(chttpd:header_value(Req, "X-Cloudant-User"),
- chttpd:header_value(Req, "Host")),
- {ok, Info} = ?COUCH:get_db_info(Db, Customer),
+ {ok, Info} = fabric:get_db_info(Db),
CurrentEtag = chttpd:make_etag(Info),
chttpd:etag_respond(Req, CurrentEtag, fun() ->
TotalRowCount = couch_util:get_value(doc_count, Info),
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index d096bff9..9566ec28 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -58,7 +58,7 @@ json_req_obj(#httpd{mochi_req=Req,
method=Verb,
path_parts=Path,
req_body=ReqBody
- }, Db) ->
+ } = HttpReq, Db) ->
Body = case ReqBody of
undefined -> Req:recv_body();
Else -> Else
@@ -71,12 +71,10 @@ json_req_obj(#httpd{mochi_req=Req,
end,
Headers = Req:get(headers),
Hlist = mochiweb_headers:to_list(Headers),
- Customer = cloudant_util:customer_name(
- Req:get_header_value("X-Cloudant-User"), Req:get_header_value("Host")),
- {ok, Info} = ?COUCH:get_db_info(Db, Customer),
+ {ok, Info} = fabric:get_db_info(Db),
% send correct path to customer - BugzID 6849
- CustomerBin = list_to_binary(Customer),
+ CustomerBin = list_to_binary(cloudant_util:customer_name(HttpReq)),
Len = byte_size(CustomerBin),
FixedPath = case Path of
[<<CustomerBin:Len/binary, "/", DbName/binary>> | Rest] ->
@@ -86,7 +84,7 @@ json_req_obj(#httpd{mochi_req=Req,
end,
% add headers...
- {[{<<"info">>, {Info}},
+ {[{<<"info">>, {cloudant_util:customer_db_info(HttpReq, Info)}},
{<<"verb">>, Verb},
{<<"path">>, FixedPath},
{<<"query">>, to_json_terms(Req:parse_qs())},
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 8867dfbe..f67ebf22 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -87,8 +87,7 @@ handle_sleep_req(Req) ->
send_method_not_allowed(Req, "GET,HEAD").
handle_all_dbs_req(#httpd{method='GET'}=Req) ->
- Customer = cloudant_util:customer_name(chttpd:header_value(Req, "X-Cloudant-User"),
- chttpd:header_value(Req, "Host")),
+ Customer = cloudant_util:customer_name(Req),
{ok, DbNames} = fabric:all_dbs(Customer),
send_json(Req, DbNames);
handle_all_dbs_req(Req) ->