diff options
Diffstat (limited to 'src/couchdb/couch_httpd_db.erl')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 29430cb6..4295ed77 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -652,33 +652,36 @@ couch_doc_open(Db, DocId, Rev, Options) -> db_attachment_req(#httpd{method='GET'}=Req, Db, DocId, FileNameParts) -> FileName = list_to_binary(mochiweb_util:join(lists:map(fun binary_to_list/1, FileNameParts),"/")), - case couch_db:open_doc(Db, DocId, []) of - {ok, #doc{attachments=Attachments}=Doc} -> - case proplists:get_value(FileName, Attachments) of - undefined -> - throw({not_found, "Document is missing attachment"}); - {Type, Bin} -> - {ok, Resp} = start_chunked_response(Req, 200, [ - {"ETag", couch_httpd:doc_etag(Doc)}, - {"Cache-Control", "must-revalidate"}, - {"Content-Type", binary_to_list(Type)}%, - % My understanding of http://www.faqs.org/rfcs/rfc2616.html - % says that we should not use Content-Length with a chunked - % encoding. Turning this off makes libcurl happy, but I am - % open to discussion. - % {"Content-Length", integer_to_list(couch_doc:bin_size(Bin))} - ]), - couch_doc:bin_foldl(Bin, - fun(BinSegment, []) -> - send_chunk(Resp, BinSegment), - {ok, []} - end, - [] - ), - send_chunk(Resp, "") - end; - Error -> - throw(Error) + #doc_query_args{ + rev=Rev, + options=Options + } = parse_doc_query(Req), + #doc{ + attachments=Attachments + } = Doc = couch_doc_open(Db, DocId, Rev, Options), + + case proplists:get_value(FileName, Attachments) of + undefined -> + throw({not_found, "Document is missing attachment"}); + {Type, Bin} -> + {ok, Resp} = start_chunked_response(Req, 200, [ + {"ETag", couch_httpd:doc_etag(Doc)}, + {"Cache-Control", "must-revalidate"}, + {"Content-Type", binary_to_list(Type)}%, + % My understanding of http://www.faqs.org/rfcs/rfc2616.html + % says that we should not use Content-Length with a chunked + % encoding. Turning this off makes libcurl happy, but I am + % open to discussion. + % {"Content-Length", integer_to_list(couch_doc:bin_size(Bin))} + ]), + couch_doc:bin_foldl(Bin, + fun(BinSegment, []) -> + send_chunk(Resp, BinSegment), + {ok, []} + end, + [] + ), + send_chunk(Resp, "") end; |