From 76508853716f2c0567bb08dfb586a6f326ee54e2 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 13 Feb 2009 03:55:36 +0000 Subject: Accept standalone attachment PUTs with Transfer-Encoding: chunked Includes a patch to mochiweb_request that is under review for inclusion upstream. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@743971 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/couchdb/couch_httpd_db.erl') diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index ae925123..89f8ce04 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -585,18 +585,31 @@ db_attachment_req(#httpd{method='GET'}=Req, Db, DocId, FileNameParts) -> db_attachment_req(#httpd{method=Method}=Req, Db, DocId, FileNameParts) when (Method == 'PUT') or (Method == 'DELETE') -> - FileName = list_to_binary(mochiweb_util:join(lists:map(fun binary_to_list/1, FileNameParts),"/")), + FileName = list_to_binary(mochiweb_util:join(lists:map(fun binary_to_list/1, + FileNameParts),"/")), NewAttachment = case Method of 'DELETE' -> []; _ -> + % see couch_db:doc_flush_binaries for usage of this structure [{FileName, { - list_to_binary(couch_httpd:header_value(Req,"Content-Type")), + case couch_httpd:header_value(Req,"Content-Type") of + undefined -> + % We could throw an error here or guess by the FileName. + % Currently, just giving it a default. + <<"application/octet-stream">>; + CType -> + list_to_binary(CType) + end, case couch_httpd:header_value(Req,"Content-Length") of undefined -> - throw({bad_request, "Attachment uploads must be fixed length"}); + {fun(MaxChunkSize, ChunkFun, InitState) -> + couch_httpd:recv_chunked(Req, MaxChunkSize, + ChunkFun, InitState) + end, undefined}; Length -> - {fun() -> couch_httpd:recv(Req, 0) end, list_to_integer(Length)} + {fun() -> couch_httpd:recv(Req, 0) end, + list_to_integer(Length)} end }}] end, -- cgit v1.2.3