couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1031369 - /couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
Date Fri, 05 Nov 2010 00:20:34 GMT
Author: fdmanana
Date: Fri Nov  5 00:20:34 2010
New Revision: 1031369

URL: http://svn.apache.org/viewvc?rev=1031369&view=rev
Log:
New replicator: deal with http request headers more gracefully.

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

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=1031369&r1=1031368&r2=1031369&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 Fri Nov  5 00:20:34
2010
@@ -26,32 +26,30 @@
 
 send_req(#httpdb{headers = BaseHeaders} = HttpDb, Params, Callback) ->
     Method = get_value(method, Params, get),
-    Headers1 = get_value(headers, Params, []),
-    {Body, Headers} = case get_value(body, Params, []) of
+    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),
-        {{NewBodyFun, Acc0}, [{"Transfer-Encoding", "chunked"} | Headers1]};
+        NewHeaders = lists:keystore(
+            "Transfer-Encoding", 1, Headers, {"Transfer-Encoding", "chunked"}),
+        {{NewBodyFun, Acc0}, NewHeaders};
     Else ->
-        {Else, Headers1}
-    end,
-    Headers2 = case {Method, Body} of
-    {put, []} ->
-        lists:keystore("Content-Length", 1, Headers, {"Content-Length", 0});
-    {post, []} ->
-        lists:keystore("Content-Length", 1, Headers, {"Content-Length", 0});
-    _ ->
-        Headers
+        {Else, Headers}
     end,
     IbrowseOptions = [
         {response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout},
         {socket_options, [{reuseaddr, true}, {keepalive, true}]}
         | get_value(ibrowse_options, Params, []) ++ HttpDb#httpdb.proxy_options
     ],
-    Headers3 = oauth_header(HttpDb, Params) ++ BaseHeaders ++ Headers2,
+    Headers2 = oauth_header(HttpDb, Params) ++ Headers1,
     Url = full_url(HttpDb, Params),
     {ok, Worker} = ibrowse:spawn_link_worker_process(Url),
     Response = ibrowse:send_req_direct(
-            Worker, Url, Headers3, Method, Body, IbrowseOptions, infinity),
+            Worker, Url, Headers2, Method, Body, IbrowseOptions, infinity),
     process_response(Response, Worker, HttpDb, Params, Callback).
 
 



Mime
View raw message