Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 24558 invoked from network); 10 Nov 2010 19:23:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Nov 2010 19:23:49 -0000 Received: (qmail 24116 invoked by uid 500); 10 Nov 2010 19:24:20 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 24088 invoked by uid 500); 10 Nov 2010 19:24:20 -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 24076 invoked by uid 99); 10 Nov 2010 19:24:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Nov 2010 19:24:19 +0000 X-ASF-Spam-Status: No, hits=-1996.4 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Nov 2010 19:24:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 686ED23889EA; Wed, 10 Nov 2010 19:23:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1033654 - in /couchdb/branches/new_replicator/src/couchdb: couch_api_wrap.erl couch_api_wrap_httpc.erl Date: Wed, 10 Nov 2010 19:23:05 -0000 To: commits@couchdb.apache.org From: fdmanana@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101110192305.686ED23889EA@eris.apache.org> 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)])).