Author: fdmanana
Date: Wed Nov 10 19:23:05 2010
New Revision: 1033654

URL: http://svn.apache.org/viewvc?rev=1033654&view=rev
Log:
New replicator: with ibrowse 2.1.0 it's no longer needed to add chunk headers 
when streaming uploads.

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.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=1033654&r1=1033653&r2=1033654&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Wed Nov 10 
19:23:05 2010
@@ -269,7 +269,7 @@ update_docs(Db, DocList, Options) ->
 
 update_docs(#httpdb{} = HttpDb, DocList, Options, UpdateType) ->
     FullCommit = atom_to_list(not lists:member(delay_commit, Options)),
-    Part1 = case UpdateType of
+    Prefix1 = case UpdateType of
     replicated_changes ->
         {prefix, <<"{\"new_edits\":false,\"docs\":[">>};
     interactive_edit ->
@@ -295,7 +295,8 @@ update_docs(#httpdb{} = HttpDb, DocList,
     send_req(
         HttpDb,
         [{method, post}, {path, "_bulk_docs"},
-            {body, {chunkify, BodyFun, [Part1 | DocList]}},
+            {body, {BodyFun, [Prefix1 | DocList]}},
+            {ibrowse_options, [{transfer_encoding, chunked}]},
             {headers, [
                 {"X-Couch-Full-Commit", FullCommit},
                 {"Content-Type", "application/json"} ]}],

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl?rev=1033654&r1=1033653&r2=1033654&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl 
(original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl Wed 
Nov 10 19:23:05 2010
@@ -28,18 +28,13 @@
 send_req(#httpdb{headers = BaseHeaders} = HttpDb, Params, Callback) ->
     Method = get_value(method, Params, get),
     Headers = get_value(headers, Params, []) ++ BaseHeaders,
-    {Body, Headers1} = case get_value(body, Params, []) of
-    [] when Method =:= put ; Method =:= post ->
-        NewHeaders = lists:keystore(
-            "Content-Length", 1, Headers, {"Content-Length", 0}),
-        {[], NewHeaders};
-    {chunkify, BodyFun, Acc0} ->
-        NewBodyFun = chunkify_fun(BodyFun),
-        NewHeaders = lists:keystore(
-            "Transfer-Encoding", 1, Headers, {"Transfer-Encoding", "chunked"}),
-        {{NewBodyFun, Acc0}, NewHeaders};
-    Else ->
-        {Else, Headers}
+    Body = get_value(body, Params, []),
+    Headers1 = case (Body =:= [] orelse Body =:= <<>>) andalso
+        (Method =:= put orelse Method =:= post) of
+    true ->
+        lists:keystore("Content-Length", 1, Headers, {"Content-Length", 0});
+    false ->
+        Headers
     end,
     IbrowseOptions = [
         {response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout},
@@ -219,21 +214,3 @@ redirect_url(RespHeaders, OrigUrl) ->
 after_redirect(RedirectUrl, HttpDb, Params) ->
     Params2 = lists:keydelete(path, 1, lists:keydelete(qs, 1, Params)),
     {HttpDb#httpdb{url = RedirectUrl}, Params2}.
-
-
-chunkify_fun(BodyFun) ->
-    fun(eof_body_fun) ->
-        eof;
-    (Acc) ->
-        case BodyFun(Acc) of
-        eof ->
-            {ok, <<"0\r\n\r\n">>, eof_body_fun};
-        {ok, Data, NewAcc} ->
-            DataBin = iolist_to_binary(Data),
-            Chunk = [hex_size(DataBin), "\r\n", DataBin, "\r\n"],
-            {ok, iolist_to_binary(Chunk), NewAcc}
-        end
-    end.
-
-hex_size(Bin) ->
-    hd(io_lib:format("~.16B", [size(Bin)])).


Reply via email to