From e1dda6bc6219d7ac33ea75d56b9c02f5063b4787 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 12 Aug 2010 11:31:13 -0400 Subject: remove some cloudant stuff --- ebin/chttpd.app | 3 +-- src/chttpd.erl | 39 +++++---------------------------------- src/chttpd_db.erl | 2 +- src/chttpd_external.erl | 17 ++++------------- src/chttpd_misc.erl | 23 +++-------------------- src/chttpd_view.erl | 4 ---- 6 files changed, 14 insertions(+), 74 deletions(-) diff --git a/ebin/chttpd.app b/ebin/chttpd.app index a6a5f2b5..a32f4786 100644 --- a/ebin/chttpd.app +++ b/ebin/chttpd.app @@ -12,8 +12,7 @@ chttpd_rewrite, chttpd_show, chttpd_sup, - chttpd_view, - cloudant_auth + chttpd_view ]}, {registered, [chttpd_sup, chttpd]}, {applications, [kernel, stdlib, couch, fabric]}, diff --git a/src/chttpd.erl b/src/chttpd.erl index 0c4d2d70..7bad9be2 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(#httpd{mochi_req=MochiReq}), - {Path, _, _} = mochiweb_util:urlsplit_path(generate_customer_path(RawUri, - Customer)), + {"/" ++ Path, _, _} = mochiweb_util:urlsplit_path(RawUri), {HandlerKey, _, _} = mochiweb_util:partition(Path, "/"), LogForClosedSocket = io_lib:format("mochiweb_recv_error for ~s - ~p ~s", [ @@ -104,7 +102,7 @@ handle_request(MochiReq) -> case authenticate_request(HttpReq, AuthenticationFuns) of #httpd{} = Req -> HandlerFun = url_handler(HandlerKey), - HandlerFun(cloudant_auth:authorize_request(Req)); + HandlerFun(Req); Response -> Response end @@ -140,35 +138,12 @@ handle_request(MochiReq) -> Peer = MochiReq:get(peer), Code = Resp:get(code), Host = MochiReq:get_header_value("Host"), - couch_metrics_event:notify(#response{ - peer = Peer, - host = Host, - customer = Customer, - code = Code, - time = RequestTime, - method = Method1, - uri = RawUri - }), - showroom_log:message(notice, "~s ~s ~s ~s ~B ~B", [Peer, Host, + ?LOG_INFO("~s ~s ~s ~s ~B ~B", [Peer, Host, atom_to_list(Method1), RawUri, Code, round(RequestTime)]), couch_stats_collector:record({couchdb, request_time}, RequestTime), couch_stats_collector:increment({httpd, requests}), {ok, Resp}. -generate_customer_path("/", _Customer) -> - ""; -generate_customer_path("/favicon.ico", _Customer) -> - "favicon.ico"; -generate_customer_path([$/,$_|Rest], _Customer) -> - lists:flatten([$_|Rest]); -generate_customer_path([$/|RawPath], Customer) -> - case Customer of - "" -> - RawPath; - Else -> - lists:flatten([Else, "%2F", RawPath]) - end. - % Try authentication handlers in order until one returns a result authenticate_request(#httpd{user_ctx=#user_ctx{}} = Req, _AuthFuns) -> Req; @@ -206,10 +181,8 @@ url_handler("_sleep") -> fun chttpd_misc:handle_sleep_req/1; url_handler("_session") -> fun chttpd_auth:handle_session_req/1; url_handler("_user") -> fun chttpd_auth:handle_user_req/1; url_handler("_oauth") -> fun chttpd_oauth:handle_oauth_req/1; -url_handler("_metrics") -> fun chttpd_misc:handle_metrics_req/1; url_handler("_restart") -> fun showroom_http:handle_restart_req/1; url_handler("_membership") -> fun mem3_httpd:handle_membership_req/1; -url_handler("_cloudant") -> fun showroom_httpd_admin:handle_cloudant_req/1; url_handler(_) -> fun chttpd_db:handle_request/1. db_url_handlers() -> @@ -265,7 +238,7 @@ qs(#httpd{mochi_req=MochiReq}) -> path(#httpd{mochi_req=MochiReq}) -> MochiReq:get(path). -absolute_uri(#httpd{mochi_req=MochiReq} = Req, Path) -> +absolute_uri(#httpd{mochi_req=MochiReq}, Path) -> XHost = couch_config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"), Host = case MochiReq:get_header_value(XHost) of undefined -> @@ -290,9 +263,7 @@ absolute_uri(#httpd{mochi_req=MochiReq} = Req, Path) -> _ -> "http" end end, - CustomerRegex = ["^/", cloudant_util:customer_name(Req), "[/%2F]+"], - NewPath = re:replace(Path, CustomerRegex, "/", [{return,list}]), - Scheme ++ "://" ++ Host ++ NewPath. + Scheme ++ "://" ++ Host ++ Path. unquote(UrlEncodedString) -> mochiweb_util:unquote(UrlEncodedString). diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl index bd11683b..e01dffeb 100644 --- a/src/chttpd_db.erl +++ b/src/chttpd_db.erl @@ -179,7 +179,7 @@ db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) -> {ok, DbInfo} = fabric:get_db_info(DbName), DeltaT = timer:now_diff(now(), T0) / 1000, couch_stats_collector:record({couchdb, dbinfo}, DeltaT), - send_json(Req, {cloudant_util:customer_db_info(Req, DbInfo)}); + send_json(Req, {DbInfo}); db_req(#httpd{method='POST', path_parts=[DbName], user_ctx=Ctx}=Req, Db) -> couch_httpd:validate_ctype(Req, "application/json"), diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl index ffde0ee7..51f32e10 100644 --- a/src/chttpd_external.erl +++ b/src/chttpd_external.erl @@ -63,7 +63,7 @@ json_req_obj(#httpd{mochi_req=Req, method=Method, path_parts=Path, req_body=ReqBody - } = HttpReq, Db, DocId) -> + }, Db, DocId) -> Body = case ReqBody of undefined -> Req:recv_body(); Else -> Else @@ -78,27 +78,18 @@ json_req_obj(#httpd{mochi_req=Req, Hlist = mochiweb_headers:to_list(Headers), {ok, Info} = fabric:get_db_info(Db), - % send correct path to customer - BugzID 6849 - CustomerBin = list_to_binary(cloudant_util:customer_name(HttpReq)), - Len = byte_size(CustomerBin), - FixedPath = case Path of - [<> | Rest] -> - [DbName | Rest]; - NoCustomer -> - NoCustomer - end, % add headers... - {[{<<"info">>, {cloudant_util:customer_db_info(HttpReq, Info)}}, + {[{<<"info">>, {Info}}, {<<"id">>, DocId}, {<<"method">>, Method}, - {<<"path">>, FixedPath}, + {<<"path">>, Path}, {<<"query">>, json_query_keys(to_json_terms(Req:parse_qs()))}, {<<"headers">>, to_json_terms(Hlist)}, {<<"body">>, Body}, {<<"peer">>, ?l2b(Req:get(peer))}, {<<"form">>, to_json_terms(ParsedForm)}, {<<"cookie">>, to_json_terms(Req:parse_cookie())}, - {<<"userCtx">>, couch_util:json_user_ctx(Db#db{name=hd(FixedPath)})}]}. + {<<"userCtx">>, couch_util:json_user_ctx(Db)}]}. to_json_terms(Data) -> to_json_terms(Data, []). diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl index 77d40b16..9a05f69e 100644 --- a/src/chttpd_misc.erl +++ b/src/chttpd_misc.erl @@ -16,8 +16,7 @@ handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1, handle_uuids_req/1,handle_config_req/1,handle_log_req/1, handle_task_status_req/1,handle_sleep_req/1,handle_welcome_req/1, - handle_utils_dir_req/1, handle_favicon_req/1, handle_metrics_req/1, - handle_system_req/1]). + handle_utils_dir_req/1, handle_favicon_req/1, handle_system_req/1]). -include_lib("couch/include/couch_db.hrl"). @@ -36,7 +35,7 @@ handle_welcome_req(#httpd{method='GET'}=Req, WelcomeMessage) -> send_json(Req, {[ {couchdb, WelcomeMessage}, {version, list_to_binary(couch:version())}, - {cloudant_build, get_version()} + {dbcore, get_version()} ]}); handle_welcome_req(Req, _) -> send_method_not_allowed(Req, "GET,HEAD"). @@ -89,8 +88,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(Req), - {ok, DbNames} = fabric:all_dbs(Customer), + {ok, DbNames} = fabric:all_dbs(), send_json(Req, DbNames); handle_all_dbs_req(Req) -> send_method_not_allowed(Req, "GET,HEAD"). @@ -209,21 +207,6 @@ handle_log_req(#httpd{method='GET'}=Req) -> handle_log_req(Req) -> send_method_not_allowed(Req, "GET"). -handle_metrics_req(#httpd{method='GET', path_parts=[_]}=Req) -> - {_, L} = lists:unzip(gen_event:which_handlers(couch_metrics_event_manager)), - send_json(Req, L); -handle_metrics_req(#httpd{method='GET', path_parts=[_, Id]}=Req) -> - case chttpd:qs_value(Req, "slice") of - undefined -> - Data = couch_metrics_event:get_global_metrics(?b2a(Id)); - SliceStr -> - Slice = list_to_integer(SliceStr), - Data = couch_metrics_event:get_global_metrics(?b2a(Id), Slice) - end, - send_json(Req, Data); -handle_metrics_req(Req) -> - send_method_not_allowed(Req, "GET,HEAD"). - % Note: this resource is exposed on the backdoor interface, but it's in chttpd % because it's not couch trunk handle_system_req(Req) -> diff --git a/src/chttpd_view.erl b/src/chttpd_view.erl index e09487c8..87a03307 100644 --- a/src/chttpd_view.erl +++ b/src/chttpd_view.erl @@ -258,10 +258,6 @@ validate_view_query(include_docs, true, Args) -> end; validate_view_query(include_docs, _Value, Args) -> Args; -validate_view_query(show_total_rows, false, Args) -> - Args#view_query_args{show_total_rows=false}; -validate_view_query(show_total_rows, _Value, Args) -> - Args; validate_view_query(sorted, false, Args) -> Args#view_query_args{sorted=false}; validate_view_query(sorted, _Value, Args) -> -- cgit v1.2.3