Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DF7161040B for ; Sat, 25 Jan 2014 01:04:50 +0000 (UTC) Received: (qmail 20757 invoked by uid 500); 25 Jan 2014 01:04:12 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 20217 invoked by uid 500); 25 Jan 2014 01:03:56 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 19673 invoked by uid 99); 25 Jan 2014 01:03:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jan 2014 01:03:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A20AD905404; Sat, 25 Jan 2014 01:03:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davisp@apache.org To: commits@couchdb.apache.org Date: Sat, 25 Jan 2014 01:04:16 -0000 Message-Id: <3fce5e2d9ae04acaba04d2a1f0d73c9b@git.apache.org> In-Reply-To: <75b75a8ec461434eaf9eb49622020916@git.apache.org> References: <75b75a8ec461434eaf9eb49622020916@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [36/42] couchdb commit: updated refs/heads/1953-fix-mime-multipart-parsing to 94b93f7 Move addition of qs params after normalization This refactor executes normalize_path/1 before appending the bound query string parameters. COUCHDB-2031 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/147adec8 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/147adec8 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/147adec8 Branch: refs/heads/1953-fix-mime-multipart-parsing Commit: 147adec8ef3763cb1821f411f393d6560aaccad2 Parents: eabece1 Author: Adam Kocoloski Authored: Sat Jan 18 00:31:49 2014 -0500 Committer: Adam Kocoloski Committed: Sat Jan 18 00:31:49 2014 -0500 ---------------------------------------------------------------------- src/couchdb/couch_httpd_rewrite.erl | 54 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/147adec8/src/couchdb/couch_httpd_rewrite.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl index 1187397..4354215 100644 --- a/src/couchdb/couch_httpd_rewrite.erl +++ b/src/couchdb/couch_httpd_rewrite.erl @@ -143,36 +143,32 @@ handle_rewrite_req(#httpd{ DispatchList = [make_rule(Rule) || {Rule} <- Rules], Method1 = couch_util:to_binary(Method), - %% get raw path by matching url to a rule. - RawPath = case try_bind_path(DispatchList, Method1, - PathParts, QueryList) of - no_dispatch_path -> - throw(not_found); - {NewPathParts, Bindings} -> - Parts = [quote_plus(X) || X <- NewPathParts], - - % build new path, reencode query args, eventually convert - % them to json - Bindings1 = maybe_encode_bindings(Bindings), - Path = binary_to_list( - iolist_to_binary([ - string:join(Parts, [?SEPARATOR]), - [["?", mochiweb_util:urlencode(Bindings1)] - || Bindings1 =/= [] ] - ])), - - % if path is relative detect it and rewrite path - case mochiweb_util:safe_relative_path(Path) of - undefined -> - ?b2l(Prefix) ++ "/" ++ Path; - P1 -> - ?b2l(Prefix) ++ "/" ++ P1 - end + % get raw path by matching url to a rule. Throws not_found. + {NewPathParts0, Bindings0} = + try_bind_path(DispatchList, Method1, PathParts, QueryList), + NewPathParts = [quote_plus(X) || X <- NewPathParts0], + Bindings = maybe_encode_bindings(Bindings0), + + Path0 = string:join(NewPathParts, [?SEPARATOR]), + + % if path is relative detect it and rewrite path + Path1 = case mochiweb_util:safe_relative_path(Path0) of + undefined -> + ?b2l(Prefix) ++ "/" ++ Path0; + P1 -> + ?b2l(Prefix) ++ "/" ++ P1 + end, + + Path2 = normalize_path(Path1), - end, + Path3 = case Bindings of + [] -> + Path2; + _ -> + [Path2, "?", mochiweb_util:urlencode(Bindings)] + end, - % normalize final path (fix levels "." and "..") - RawPath1 = ?b2l(iolist_to_binary(normalize_path(RawPath))), + RawPath1 = ?b2l(iolist_to_binary(Path3)), % In order to do OAuth correctly, we have to save the % requested path. We use default so chained rewriting @@ -216,7 +212,7 @@ quote_plus(X) -> %% @doc Try to find a rule matching current url. If none is found %% 404 error not_found is raised try_bind_path([], _Method, _PathParts, _QueryList) -> - no_dispatch_path; + throw(not_found); try_bind_path([Dispatch|Rest], Method, PathParts, QueryList) -> [{PathParts1, Method1}, RedirectPath, QueryArgs, Formats] = Dispatch, case bind_method(Method1, Method) of