You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2009/05/05 00:25:24 UTC

svn commit: r771474 - in /couchdb/trunk: share/www/script/test/attachments.js src/couchdb/couch_httpd_db.erl

Author: kocolosk
Date: Mon May  4 22:25:23 2009
New Revision: 771474

URL: http://svn.apache.org/viewvc?rev=771474&view=rev
Log:
standalone attachment GETs should respect "rev" qs param

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=771474&r1=771473&r2=771474&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/attachments.js (original)
+++ couchdb/trunk/share/www/script/test/attachments.js Mon May  4 22:25:23 2009
@@ -117,9 +117,15 @@
   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"},

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=771474&r1=771473&r2=771474&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Mon May  4 22:25:23 2009
@@ -652,33 +652,36 @@
 
 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;