couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r792774 - in /couchdb/trunk: share/www/script/test/attachments.js src/couchdb/couch_httpd_db.erl
Date Fri, 10 Jul 2009 01:17:16 GMT
Author: jchris
Date: Fri Jul 10 01:17:15 2009
New Revision: 792774

URL: http://svn.apache.org/viewvc?rev=792774&view=rev
Log:
fix attachment etags, thanks Mark Hammond for the test case. closes COUCHDB-386

Modified:
    couchdb/trunk/share/www/script/test/attachments.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/attachments.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/attachments.js?rev=792774&r1=792773&r2=792774&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/attachments.js (original)
+++ couchdb/trunk/share/www/script/test/attachments.js Fri Jul 10 01:17:15 2009
@@ -202,4 +202,13 @@
   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);
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=792774&r1=792773&r2=792774&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Jul 10 01:17:15 2009
@@ -774,19 +774,22 @@
     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;
 
 



Mime
View raw message