summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2008-12-29 20:14:37 +0000
committerJan Lehnardt <jan@apache.org>2008-12-29 20:14:37 +0000
commit46874e0e90a46fefe0a6f7e1ef574bb6a2fcaf78 (patch)
treeed4692f9b8b3f31b1f35c4e01483b0fdf9ad14f3
parentcf018e7bf9b5673a1bd885e23dac7c92ee2fe968 (diff)
add etags to standalone attachment requests. Closes COUCHDB-184
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@729992 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/couch_tests.js4
-rw-r--r--src/couchdb/couch_httpd_db.erl3
2 files changed, 5 insertions, 2 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 8a00dc93..1eb1836e 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -795,11 +795,13 @@ var tests = {
}
}
- T(db.save(binAttDoc).ok);
+ var save_response = db.save(binAttDoc);
+ T(save_response.ok);
var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt");
T(xhr.responseText == "This is a base64 encoded text");
T(xhr.getResponseHeader("Content-Type") == "text/plain");
+ T(xhr.getResponseHeader("Etag") == save_response.rev);
// empty attachment
var binAttDoc2 = {
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 16956a86..eb41801f 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -513,12 +513,13 @@ 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}} ->
+ {ok, #doc{attachments=Attachments, revs=[LastRev|_OldRevs]}} ->
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", binary_to_list(LastRev)},
{"Cache-Control", "must-revalidate"},
{"Content-Type", binary_to_list(Type)}%,
% My understanding of http://www.faqs.org/rfcs/rfc2616.html