From ba94c9c5c85c82804faa91d8d2938539168ea965 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Mon, 4 May 2009 22:25:23 +0000 Subject: standalone attachment GETs should respect "rev" qs param git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@771474 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'src/couchdb') 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; -- cgit v1.2.3