Author: fdmanana
Date: Wed Sep 22 18:53:49 2010
New Revision: 1000140

URL: http://svn.apache.org/viewvc?rev=1000140&view=rev
Log:
Replicator: avoid percent encoding the slashes of design and local document IDs.
This avoids receiving and following redirect responses from the peer. It also 
removes the eventual need of special rules in proxies (like Apache httpd).

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl
    couchdb/trunk/src/couchdb/couch_rep_reader.erl
    couchdb/trunk/src/couchdb/couch_rep_writer.erl
    couchdb/trunk/src/couchdb/couch_util.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=1000140&r1=1000139&r2=1000140&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Wed Sep 22 18:53:49 2010
@@ -557,7 +557,7 @@ fold_replication_logs([Db|Rest]=Dbs, Vsn
     end.
 
 open_replication_log(#http_db{}=Db, DocId) ->
-    Req = Db#http_db{resource=couch_util:url_encode(?b2l(DocId))},
+    Req = Db#http_db{resource=couch_util:encode_doc_id(DocId)},
     case couch_rep_httpc:request(Req) of
     {[{<<"error">>, _}, {<<"reason">>, _}]} ->
         ?LOG_DEBUG("didn't find a replication log for ~s", [Db#http_db.url]),
@@ -767,9 +767,9 @@ ensure_full_commit(Source, RequiredSeq) 
         InstanceStartTime
     end.
 
-update_local_doc(#http_db{} = Db, #doc{id=DocId} = Doc) ->
+update_local_doc(#http_db{} = Db, Doc) ->
     Req = Db#http_db{
-        resource = couch_util:url_encode(DocId),
+        resource = couch_util:encode_doc_id(Doc),
         method = put,
         body = couch_doc:to_json_obj(Doc, [attachments]),
         headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers]

Modified: couchdb/trunk/src/couchdb/couch_rep_reader.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep_reader.erl?rev=1000140&r1=1000139&r2=1000140&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep_reader.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep_reader.erl Wed Sep 22 18:53:49 2010
@@ -17,7 +17,7 @@
 
 -export([start_link/4, next/1]).
 
--import(couch_util, [url_encode/1]).
+-import(couch_util, [encode_doc_id/1]).
 
 -define (BUFFER_SIZE, 1000).
 -define (MAX_CONCURRENT_REQUESTS, 100).
@@ -234,7 +234,7 @@ open_doc_revs(#http_db{url = Url} = DbS,
     %% all this logic just splits up revision lists that are too long for
     %% MochiWeb into multiple requests
     BaseQS = [{revs,true}, {latest,true}, {att_encoding_info,true}],
-    BaseReq = DbS#http_db{resource=url_encode(DocId), qs=BaseQS},
+    BaseReq = DbS#http_db{resource=encode_doc_id(DocId), qs=BaseQS},
     BaseLength = length(couch_rep_httpc:full_url(BaseReq)) + 11, % &open_revs=
 
     {RevLists, _, _} = lists:foldl(fun split_revlist/2,
@@ -264,7 +264,7 @@ open_doc_revs(#http_db{url = Url} = DbS,
 open_doc(#http_db{url = Url} = DbS, DocId) ->
     % get latest rev of the doc
     Req = DbS#http_db{
-        resource=url_encode(DocId),
+        resource=encode_doc_id(DocId),
         qs=[{att_encoding_info, true}]
     },
     {Props} = Json = couch_rep_httpc:request(Req),

Modified: couchdb/trunk/src/couchdb/couch_rep_writer.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep_writer.erl?rev=1000140&r1=1000139&r2=1000140&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep_writer.erl Wed Sep 22 18:53:49 2010
@@ -119,7 +119,7 @@ write_multi_part_doc(#http_db{headers=He
         end
     end,
     Request = Db#http_db{
-        resource = couch_util:url_encode(Doc#doc.id),
+        resource = couch_util:encode_doc_id(Doc),
         method = put,
         qs = [{new_edits, false}],
         body = {BodyFun, nil},

Modified: couchdb/trunk/src/couchdb/couch_util.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=1000140&r1=1000139&r2=1000140&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_util.erl (original)
+++ couchdb/trunk/src/couchdb/couch_util.erl Wed Sep 22 18:53:49 2010
@@ -28,6 +28,7 @@
 -export([md5/1, md5_init/0, md5_update/2, md5_final/1]).
 -export([reorder_results/2]).
 -export([url_strip_password/1]).
+-export([encode_doc_id/1]).
 
 -include("couch_db.hrl").
 -include_lib("kernel/include/file.hrl").
@@ -439,3 +440,14 @@ url_strip_password(Url) ->
         "http(s)?://([^:]+):[...@]+@(.*)$",
         "http\\1://\\2:**...@\\3",
         [{return, list}]).
+
+encode_doc_id(#doc{id = Id}) ->
+    encode_doc_id(Id);
+encode_doc_id(Id) when is_list(Id) ->
+    encode_doc_id(?l2b(Id));
+encode_doc_id(<<"_design/", Rest/binary>>) ->
+    "_design/" ++ url_encode(Rest);
+encode_doc_id(<<"_local/", Rest/binary>>) ->
+    "_local/" ++ url_encode(Rest);
+encode_doc_id(Id) ->
+    url_encode(Id).


Reply via email to