You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/01/30 02:40:39 UTC
svn commit: r739133 - in /couchdb/trunk: share/www/script/couch_tests.js
src/couchdb/couch_httpd_db.erl
Author: jchris
Date: Fri Jan 30 01:40:38 2009
New Revision: 739133
URL: http://svn.apache.org/viewvc?rev=739133&view=rev
Log:
POST to create docs returns a Location header. fixes COUCHDB-8
Modified:
couchdb/trunk/share/www/script/couch_tests.js
couchdb/trunk/src/couchdb/couch_httpd_db.erl
Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=739133&r1=739132&r2=739133&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Jan 30 01:40:38 2009
@@ -140,6 +140,18 @@
// make sure we can still open
T(db.open(existingDoc._id, {rev: existingDoc._rev}) != null);
+
+ // test that the POST response has a Location header
+ var xhr = CouchDB.request("POST", "/test_suite_db", {
+ body: JSON.stringify({"foo":"bar"})
+ });
+ var resp = JSON.parse(xhr.responseText);
+ T(resp.ok);
+ var loc = xhr.getResponseHeader("Location");
+ T(loc, "should have a Location header");
+ var locs = loc.split('/');
+ T(locs[4] == resp.id);
+ T(locs[3] == "test_suite_db");
},
delayed_commits: function(debug) {
Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=739133&r1=739132&r2=739133&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Jan 30 01:40:38 2009
@@ -18,7 +18,7 @@
-import(couch_httpd,
[send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
start_json_response/2,send_chunk/2,end_json_response/1,
- start_chunked_response/3]).
+ start_chunked_response/3, absolute_uri/2]).
-record(doc_query_args, {
options = [],
@@ -76,11 +76,13 @@
{ok, DbInfo} = couch_db:get_db_info(Db),
send_json(Req, {DbInfo});
-db_req(#httpd{method='POST',path_parts=[_DbName]}=Req, Db) ->
+db_req(#httpd{method='POST',path_parts=[DbName]}=Req, Db) ->
Doc = couch_doc:from_json_obj(couch_httpd:json_body(Req)),
DocId = couch_util:new_uuid(),
{ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=[]}, []),
- send_json(Req, 201, {[
+ DocUrl = absolute_uri(Req,
+ binary_to_list(<<"/",DbName/binary,"/",DocId/binary>>)),
+ send_json(Req, 201, [{"Location", DocUrl}], {[
{ok, true},
{id, DocId},
{rev, NewRev}