summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/basics.js10
-rw-r--r--src/couchdb/couch_httpd_db.erl18
2 files changed, 22 insertions, 6 deletions
diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js
index 3979d860..34d0f38e 100644
--- a/share/www/script/test/basics.js
+++ b/share/www/script/test/basics.js
@@ -161,6 +161,16 @@ couchTests.basics = function(debug) {
T(locs[4] == resp.id);
T(locs[3] == "test_suite_db");
+ // test that that POST's with an _id aren't overriden with a UUID.
+ var xhr = CouchDB.request("POST", "/test_suite_db", {
+ body: JSON.stringify({"_id": "oppossum", "yar": "matey"})
+ });
+ var resp = JSON.parse(xhr.responseText);
+ T(resp.ok);
+ T(resp.id == "oppossum");
+ var doc = db.open("oppossum");
+ T(doc.yar == "matey");
+
// document put's should return a Location header
var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
body: JSON.stringify({"a":1})
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index a3ac69ae..8a46349a 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -271,21 +271,27 @@ db_req(#httpd{method='GET',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(),
+ Doc2 = case Doc#doc.id of
+ <<"">> ->
+ Doc#doc{id=couch_util:new_uuid(), revs={0, []}};
+ _ ->
+ Doc
+ end,
+ DocId = Doc2#doc.id,
case couch_httpd:qs_value(Req, "batch") of
"ok" ->
% batch
- ok = couch_batch_save:eventually_save_doc(Db#db.name,
- Doc#doc{id=DocId}, Db#db.user_ctx),
+ ok = couch_batch_save:eventually_save_doc(
+ Db#db.name, Doc2, Db#db.user_ctx),
send_json(Req, 202, [], {[
{ok, true},
{id, DocId}
]});
_Normal ->
% normal
- {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId}, []),
- DocUrl = absolute_uri(Req,
- binary_to_list(<<"/",DbName/binary,"/",DocId/binary>>)),
+ {ok, NewRev} = couch_db:update_doc(Db, Doc2, []),
+ DocUrl = absolute_uri(
+ Req, binary_to_list(<<"/",DbName/binary,"/", DocId/binary>>)),
send_json(Req, 201, [{"Location", DocUrl}], {[
{ok, true},
{id, DocId},