summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_doc.erl
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-05-23 10:56:08 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-05-23 10:56:08 +0000
commit1a4f2d8c5ef87933192125b3feb98eaaa33a7bbc (patch)
tree89657f44e39f9f1fa5e5a67b1f94dfb4ac4a654e /src/couchdb/couch_doc.erl
parentee6bb16b53069e6b213d1314f78cde2bd648b069 (diff)
Merged revision 1126426 from trunk
Fix timing issues in the doc PUT multipart/related API Two issues were present: 1) the handler replied to the request before the multipart parser consumed all the request's data, causing a subsequent request in the same connection to consume the remaining data from the multipart/related request; 2) the data function passed to the multipart parser could consume, and discard, all or part of the data from a subsequent request in the same connection. This closes COUCHDB-1174. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1126428 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_doc.erl')
-rw-r--r--src/couchdb/couch_doc.erl17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index e3d66145..e2690f3e 100644
--- a/src/couchdb/couch_doc.erl
+++ b/src/couchdb/couch_doc.erl
@@ -461,16 +461,17 @@ atts_to_mp([Att | RestAtts], Boundary, WriteFun,
doc_from_multi_part_stream(ContentType, DataFun) ->
- Self = self(),
+ Parent = self(),
Parser = spawn_link(fun() ->
- couch_httpd:parse_multipart_request(ContentType, DataFun,
- fun(Next)-> mp_parse_doc(Next, []) end),
- unlink(Self)
+ {<<"--">>, _, _} = couch_httpd:parse_multipart_request(
+ ContentType, DataFun,
+ fun(Next) -> mp_parse_doc(Next, []) end),
+ unlink(Parent),
+ Parent ! {self(), finished}
end),
Parser ! {get_doc_bytes, self()},
receive
{doc_bytes, DocBytes} ->
- erlang:put(mochiweb_request_recv, true),
Doc = from_json_obj(?JSON_DECODE(DocBytes)),
% go through the attachments looking for 'follows' in the data,
% replace with function that reads the data from MIME stream.
@@ -484,7 +485,11 @@ doc_from_multi_part_stream(ContentType, DataFun) ->
(A) ->
A
end, Doc#doc.atts),
- {ok, Doc#doc{atts=Atts2}}
+ WaitFun = fun() ->
+ receive {Parser, finished} -> ok end,
+ erlang:put(mochiweb_request_recv, true)
+ end,
+ {ok, Doc#doc{atts=Atts2}, WaitFun}
end.
mp_parse_doc({headers, H}, []) ->