diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-02-13 03:55:36 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-02-13 03:55:36 +0000 |
commit | 76508853716f2c0567bb08dfb586a6f326ee54e2 (patch) | |
tree | 3826927aa79d2cb2c7ea3e3405e4c9a2538c08d6 /src/couchdb/couch_httpd_db.erl | |
parent | da592618240eb9b8c165905f1d9ab4c4a3665b02 (diff) |
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
Diffstat (limited to 'src/couchdb/couch_httpd_db.erl')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 21 |
1 files changed, 17 insertions, 4 deletions
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, |