couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r758768 - in /couchdb/trunk: share/www/script/test/basics.js src/couchdb/couch_httpd_db.erl
Date Thu, 26 Mar 2009 17:40:44 GMT
Author: jan
Date: Thu Mar 26 17:40:27 2009
New Revision: 758768

URL: http://svn.apache.org/viewvc?rev=758768&view=rev
Log:
return a Location header on newly created documents using PUT requests

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

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=758768&r1=758767&r2=758768&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Thu Mar 26 17:40:27 2009
@@ -148,6 +148,13 @@
     T(locs[4] == resp.id);
     T(locs[3] == "test_suite_db");
 
+    // document put's should return a Location header
+    var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
+      body: JSON.stringify({"a":1})
+    });
+    TEquals("/test_suite_db/newdoc", xhr.getResponseHeader("Location"),
+      "should return Location header to newly created document");
+
     // deleting a non-existent doc should be 404
     xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist");
     T(xhr.status == 404);

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=758768&r1=758767&r2=758768&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Thu Mar 26 17:40:27 2009
@@ -496,7 +496,8 @@
     ]});
 
 db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) ->
-    update_doc(Req, Db, DocId, couch_httpd:json_body(Req));
+    update_doc(Req, Db, DocId, couch_httpd:json_body(Req),
+      [{"Location", "/" ++ ?b2l(Db#db.name) ++ "/" ++ ?b2l(DocId)}]);
 
 db_doc_req(#httpd{method='COPY'}=Req, Db, SourceDocId) ->
     SourceRev =
@@ -529,6 +530,9 @@
 
 
 update_doc(Req, Db, DocId, Json) ->
+    update_doc(Req, Db, DocId, Json, []).
+
+update_doc(Req, Db, DocId, Json, Headers) ->
     #doc{deleted=Deleted} = Doc = couch_doc:from_json_obj(Json),
     validate_attachment_names(Doc),
     ExplicitDocRev =
@@ -551,8 +555,9 @@
     end,
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=Revs}, Options),
     NewRevStr = couch_doc:rev_to_str(NewRev),
+    ResponseHeaders = [{"Etag", <<"\"", NewRevStr/binary, "\"">>}] ++ Headers,
     send_json(Req, if Deleted -> 200; true -> 201 end,
-        [{"Etag", <<"\"", NewRevStr/binary, "\"">>}], {[
+        ResponseHeaders, {[
             {ok, true},
             {id, DocId},
             {rev, NewRevStr}]}).



Mime
View raw message