From deae5e14975c0726feb28c7e0be433e650c40f30 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 11 Jul 2009 17:00:42 +0000 Subject: send Location header for new or updated attachments git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@793205 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/attachments.js | 7 ++++++- src/couchdb/couch_httpd_db.erl | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/share/www/script/test/attachments.js b/share/www/script/test/attachments.js index f89ec124..b31cfe0b 100644 --- a/share/www/script/test/attachments.js +++ b/share/www/script/test/attachments.js @@ -58,6 +58,10 @@ couchTests.attachments= function(debug) { headers:{"Content-Type": "text/plain;charset=utf-8"} }); T(xhr.status == 201); + TEquals("/bin_doc2/foo2.txt", + xhr.getResponseHeader("Location").substr(-18), + "should return Location header to newly created or updated attachment"); + var rev = JSON.parse(xhr.responseText).rev; binAttDoc2 = db.open("bin_doc2"); @@ -78,7 +82,8 @@ couchTests.attachments= function(debug) { // test with rev, should not fail var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt?rev=" + rev); T(xhr.status == 200); - + TEquals(null, xhr.getResponseHeader("Location"), + "should not return Location header on DELETE request"); // test binary data var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])} ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np"; diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 3b5fcbe8..3277af08 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -842,7 +842,19 @@ db_attachment_req(#httpd{method=Method}=Req, Db, DocId, FileNameParts) attachments = NewAttachment ++ proplists:delete(FileName, Attachments) }, {ok, UpdatedRev} = couch_db:update_doc(Db, DocEdited, []), - send_json(Req, case Method of 'DELETE' -> 200; _ -> 201 end, {[ + #db{name=DbName} = Db, + + {Status, Headers} = case Method of + 'DELETE' -> + {200, []}; + _ -> + {201, [{"Location", absolute_uri(Req, "/" ++ + binary_to_list(DbName) ++ "/" ++ + binary_to_list(DocId) ++ "/" ++ + binary_to_list(FileName) + )}]} + end, + send_json(Req,Status, Headers, {[ {ok, true}, {id, DocId}, {rev, couch_doc:rev_to_str(UpdatedRev)} -- cgit v1.2.3