diff options
author | Jan Lehnardt <jan@apache.org> | 2009-03-26 17:40:27 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2009-03-26 17:40:27 +0000 |
commit | 1dd554d884644bbf6f5a7d07b7c8fe51feb7a4c4 (patch) | |
tree | 44f37e75467603a54edd79280cebc22d963de60f /src/couchdb | |
parent | 39a927058a066e7c7c31cb4388371f2c8b639e4b (diff) |
return a Location header on newly created documents using PUT requests
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@758768 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 92ad98c8..78b127b4 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -496,7 +496,8 @@ db_doc_req(#httpd{method='POST'}=Req, Db, DocId) -> ]}); 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_result_to_json(Error) -> 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 @@ update_doc(Req, Db, DocId, Json) -> 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}]}). |