couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r793205 - in /couchdb/trunk: share/www/script/test/attachments.js src/couchdb/couch_httpd_db.erl
Date Sat, 11 Jul 2009 17:00:43 GMT
Author: jan
Date: Sat Jul 11 17:00:42 2009
New Revision: 793205

URL: http://svn.apache.org/viewvc?rev=793205&view=rev
Log:
send Location header for new or updated attachments

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=793205&r1=793204&r2=793205&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/attachments.js (original)
+++ couchdb/trunk/share/www/script/test/attachments.js Sat Jul 11 17:00:42 2009
@@ -58,6 +58,10 @@
     headers:{"Content-Type": "text/plain;charset=utf-8"}
   });
   T(xhr.status == 201);
+  TEquals("/bin_doc2/foo2.txt",
+    xhr.getResponseHeader("Location").substr(-18),
+    "should return Location header to newly created or updated attachment");
+  
   var rev = JSON.parse(xhr.responseText).rev;
 
   binAttDoc2 = db.open("bin_doc2");
@@ -78,7 +82,8 @@
   // test with rev, should not fail
   var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt?rev=" + rev);
   T(xhr.status == 200);
-
+  TEquals(null, xhr.getResponseHeader("Location"),
+    "should not return Location header on DELETE request");
 
   // test binary data
   var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])}    ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np";

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=793205&r1=793204&r2=793205&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Sat Jul 11 17:00:42 2009
@@ -842,7 +842,19 @@
         attachments = NewAttachment ++ proplists:delete(FileName, Attachments)
     },
     {ok, UpdatedRev} = couch_db:update_doc(Db, DocEdited, []),
-    send_json(Req, case Method of 'DELETE' -> 200; _ -> 201 end, {[
+    #db{name=DbName} = Db,
+    
+    {Status, Headers} = case Method of
+        'DELETE' ->
+            {200, []};
+        _ ->
+            {201, [{"Location", absolute_uri(Req, "/" ++ 
+                binary_to_list(DbName) ++ "/" ++ 
+                binary_to_list(DocId) ++ "/" ++ 
+                binary_to_list(FileName)
+            )}]}
+        end,
+    send_json(Req,Status, Headers, {[
         {ok, true},
         {id, DocId},
         {rev, couch_doc:rev_to_str(UpdatedRev)}



Mime
View raw message