couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject [1/3] couchdb commit: updated refs/heads/1994-merge-rcouch to 824869c
Date Wed, 29 Jan 2014 10:53:35 GMT
Updated Branches:
  refs/heads/1994-merge-rcouch 44580da65 -> 824869c3c


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/a608b83f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a608b83f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a608b83f

Branch: refs/heads/1994-merge-rcouch
Commit: a608b83fffeda84be7d24814c6c80439362083d7
Parents: 44580da
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Sat Jan 18 00:31:49 2014 -0500
Committer: Benoit Chesneau <bchesneau@gmail.com>
Committed: Wed Jan 29 11:22:23 2014 +0100

----------------------------------------------------------------------
 apps/couch_httpd/src/couch_httpd_rewrite.erl | 58 +++++++++++------------
 1 file changed, 27 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a608b83f/apps/couch_httpd/src/couch_httpd_rewrite.erl
----------------------------------------------------------------------
diff --git a/apps/couch_httpd/src/couch_httpd_rewrite.erl b/apps/couch_httpd/src/couch_httpd_rewrite.erl
index 997992f..011c3c8 100644
--- a/apps/couch_httpd/src/couch_httpd_rewrite.erl
+++ b/apps/couch_httpd/src/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
-
-                end,
-
-            % normalize final path (fix levels "." and "..")
-            RawPath1 = ?b2l(iolist_to_binary(normalize_path(RawPath))),
+            % 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),
+
+            Path3 = case Bindings of
+                [] ->
+                    Path2;
+                _ ->
+                    [Path2, "?", mochiweb_util:urlencode(Bindings)]
+            end,
+
+            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


Mime
View raw message