Skip to content

Commit

Permalink
fix attachment etags, thanks Mark Hammond for the test case. closes C…
Browse files Browse the repository at this point in the history
…OUCHDB-386

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@792774 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jchris committed Jul 10, 2009
1 parent 9ccb235 commit b67a4ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
9 changes: 9 additions & 0 deletions share/www/script/test/attachments.js
Expand Up @@ -202,4 +202,13 @@ couchTests.attachments= function(debug) {
var doc = db.open("bin_doc5", {attachments:true});
T(doc._attachments["lorem.txt"].data == lorem_b64);

// test etags for attachments.
var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc5/lorem.txt");
T(xhr.status == 200);
var etag = xhr.getResponseHeader("etag");
console.log(etag)
xhr = CouchDB.request("GET", "/test_suite_db/bin_doc5/lorem.txt", {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
};
29 changes: 16 additions & 13 deletions src/couchdb/couch_httpd_db.erl
Expand Up @@ -774,19 +774,22 @@ db_attachment_req(#httpd{method='GET'}=Req, Db, DocId, FileNameParts) ->
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) end,[]),
send_chunk(Resp, "")
Etag = couch_httpd:doc_etag(Doc),
couch_httpd:etag_respond(Req, Etag, fun() ->
{ok, Resp} = start_chunked_response(Req, 200, [
{"ETag", Etag},
{"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) end,[]),
send_chunk(Resp, "")
end)
end;


Expand Down

0 comments on commit b67a4ec

Please sign in to comment.