You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/09/05 14:23:01 UTC

svn commit: r992767 - /couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl

Author: fdmanana
Date: Sun Sep  5 12:23:00 2010
New Revision: 992767

URL: http://svn.apache.org/viewvc?rev=992767&view=rev
Log:
New replicator: moving duplicated code into a function and avoid percent encoding local doc IDs.

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl?rev=992767&r1=992766&r2=992767&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Sun Sep  5 12:23:00 2010
@@ -167,16 +167,10 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Re
         {"open_revs", ?JSON_ENCODE(couch_doc:revs_to_strs(Revs))} |
         options_to_query_args(Options, [])
     ],
-    IdEncoded = case Id of
-    <<"_design/", RestId/binary>> ->
-        "_design/" ++ url_encode(RestId);
-    _ ->
-        url_encode(Id)
-    end,
     Streamer = spawn_link(fun() ->
             send_req(
                 HttpDb,
-                [{path, IdEncoded}, {qs, QArgs},
+                [{path, encode_doc_id(Id)}, {qs, QArgs},
                     {ibrowse_options, [{stream_to, {self(), once}}]},
                     {headers, [{"accept", "multipart/mixed"}]}],
                 fun(200, Headers, StreamDataFun) ->
@@ -201,18 +195,12 @@ open_doc(#httpdb{} = HttpDb, Id, Options
         {"revs", "true"} |
         options_to_query_args(Options, [])
     ],
-    IdEncoded = case Id of
-    <<"_design/", RestId/binary>> ->
-        "_design/" ++ url_encode(RestId);
-    _ ->
-        url_encode(Id)
-    end,
     Self = self(),
     Streamer = spawn_link(fun() ->
             send_req(
                 HttpDb,
                 [{headers, [{"accept", "application/json, multipart/related"}]},
-                    {path, IdEncoded}, {qs, QArgs},
+                    {path, encode_doc_id(Id)}, {qs, QArgs},
                     {ibrowse_options, [{stream_to, {self(), once}}]}],
                 fun(Code, Headers, StreamDataFun) ->
                     CType = get_value("Content-Type", Headers),
@@ -553,3 +541,10 @@ json_to_doc_info({Props}) ->
         high_seq = get_value(<<"seq">>, Props),
         revs = RevsInfo
     }.
+
+encode_doc_id(<<"_design/", RestId/binary>>) ->
+    "_design/" ++ url_encode(RestId);
+encode_doc_id(<<"_local/", RestId/binary>>) ->
+    "_local/" ++ url_encode(RestId);
+encode_doc_id(DocId) ->
+    url_encode(DocId).