diff options
author | Joan Touzet <joant@atypical.net> | 2019-11-25 12:03:33 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2019-12-02 17:51:44 +0000 |
commit | 65b5076faccdc4cb827a40893a9c5c4ff24c91c2 (patch) | |
tree | 54557c890f675e50247f61a32d14c7223d24cf77 | |
parent | 12e8878a5bf596579021ec433c68b411d29dd930 (diff) | |
download | couchdb-65b5076faccdc4cb827a40893a9c5c4ff24c91c2.tar.gz |
Mangle request before calling handle_request
-rw-r--r-- | src/chttpd/src/chttpd_node.erl | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl index 982cd2dd6..f8736f13f 100644 --- a/src/chttpd/src/chttpd_node.erl +++ b/src/chttpd/src/chttpd_node.erl @@ -117,10 +117,21 @@ handle_node_req(#httpd{method='POST', path_parts=[_, Node, <<"_restart">>]}=Req) send_json(Req, 200, {[{ok, true}]}); handle_node_req(#httpd{path_parts=[_, _Node, <<"_restart">>]}=Req) -> send_method_not_allowed(Req, "POST"); +handle_node_req(#httpd{path_parts=[_, Node | PathParts], + mochi_req=MochiReq0}) -> + % strip /_node/{node} from Req0 before descending further + RawUri = MochiReq0:get(raw_path), + {_, Query, Fragment} = mochiweb_util:urlsplit_path(RawUri), + NewPath0 = "/" ++ lists:join("/", [?b2l(P) || P <- PathParts]), + NewRawPath = mochiweb_util:urlunsplit_path({NewPath0, Query, Fragment}), + MochiReq = mochiweb_request:new(self(), + MochiReq0:get(method), + NewRawPath, + MochiReq0:get(version), + MochiReq0:get(headers)), + call_node(Node, couch_httpd, handle_request, [MochiReq]); handle_node_req(#httpd{path_parts=[_]}=Req) -> chttpd:send_error(Req, {bad_request, <<"Incomplete path to _node request">>}); -handle_node_req(#httpd{path_parts=[_, _Node]}=Req) -> - chttpd:send_error(Req, {bad_request, <<"Incomplete path to _node request">>}); handle_node_req(Req) -> chttpd:send_error(Req, not_found). |