summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-05-04 22:25:23 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-05-04 22:25:23 +0000
commitba94c9c5c85c82804faa91d8d2938539168ea965 (patch)
tree38908c2b1c37617a160aa905f7c466a20b0055df
parent4708e0afcfeaaa9821c9910902495972fc5733ac (diff)
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
-rw-r--r--share/www/script/test/attachments.js8
-rw-r--r--src/couchdb/couch_httpd_db.erl57
2 files changed, 37 insertions, 28 deletions
diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js
index d9560bce..ec59eda4 100644
--- a/share/www/script/test/attachments.js
+++ b/share/www/script/test/attachments.js
@@ -117,9 +117,15 @@ couchTests.attachments= function(debug) {
var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
T(xhr.status == 200);
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt");
T(xhr.status == 404);
+ // deleted attachment is still accessible with revision
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
+ T(xhr.status == 200);
+ T(xhr.responseText == bin_data);
+ T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
+
// empty attachments
var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc4/attachment.txt", {
headers:{"Content-Type":"text/plain;charset=utf-8"},
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;