You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2019/11/25 17:44:23 UTC
[couchdb] 08/10: Mangle request before calling handle_request
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch 1523-bye-bye-5986-rnewson-4
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 5c8a815f56de27d22fdf7baae680b7d2dd7f7d7e
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Mon Nov 25 12:03:33 2019 +0000
Mangle request before calling handle_request
---
src/chttpd/src/chttpd_node.erl | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 0230bb9..abf6ba3 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -123,10 +123,21 @@ handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_all_dbs">>]}=Req)
send_json(Req, DbNames);
handle_node_req(#httpd{path_parts=[_, _Node, <<"_all_dbs">>]}=Req) ->
send_method_not_allowed(Req, "GET");
+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 = ?l2b("/" ++ string: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).