summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorPaul Joseph Davis <davisp@apache.org>2009-08-16 03:07:21 +0000
committerPaul Joseph Davis <davisp@apache.org>2009-08-16 03:07:21 +0000
commit58251b581684923782f879e67b13361644592a37 (patch)
tree6537b96e831e213432340c86aa1ad6486d456fb8 /src/couchdb
parent3975b8758a6aa58389a74eba15e1908ef86465d8 (diff)
Make POST's reflect a provided _id member.
Fixes COUCHDB-468 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@804555 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_httpd_db.erl18
1 files changed, 12 insertions, 6 deletions
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},