summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/basics.js16
-rw-r--r--src/couchdb/couch_httpd_db.erl6
2 files changed, 17 insertions, 5 deletions
diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js
index 7149c350..4571200e 100644
--- a/share/www/script/test/basics.js
+++ b/share/www/script/test/basics.js
@@ -31,8 +31,13 @@ couchTests.basics = function(debug) {
// creating a new DB should return Location header
xhr = CouchDB.request("DELETE", "/new-db");
xhr = CouchDB.request("PUT", "/new-db");
- TEquals("/new-db", xhr.getResponseHeader("Location"),
- "should return newly created database name in location header");
+ TEquals("/new-db",
+ xhr.getResponseHeader("Location").substr(-7),
+ "should return Location header to newly created document");
+
+ TEquals("http://",
+ xhr.getResponseHeader("Location").substr(0, 7),
+ "should return absolute Location header to newly created document");
// Get the database info, check the db_name
T(db.info().db_name == "test_suite_db");
@@ -152,9 +157,14 @@ couchTests.basics = function(debug) {
var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
body: JSON.stringify({"a":1})
});
- TEquals("/test_suite_db/newdoc", xhr.getResponseHeader("Location"),
+ TEquals("/test_suite_db/newdoc",
+ xhr.getResponseHeader("Location").substr(-21),
"should return Location header to newly created document");
+ TEquals("http://",
+ xhr.getResponseHeader("Location").substr(0, 7),
+ "should return absolute Location header to newly created document");
+
// deleting a non-existent doc should be 404
xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist");
T(xhr.status == 404);
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 78b127b4..07815bda 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -56,7 +56,8 @@ create_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) ->
case couch_server:create(DbName, [{user_ctx, UserCtx}]) of
{ok, Db} ->
couch_db:close(Db),
- send_json(Req, 201, [{"Location", "/" ++ DbName}], {[{ok, true}]});
+ DocUrl = absolute_uri(Req, "/" ++ DbName),
+ send_json(Req, 201, [{"Location", DocUrl}], {[{ok, true}]});
Error ->
throw(Error)
end.
@@ -496,8 +497,9 @@ db_doc_req(#httpd{method='POST'}=Req, Db, DocId) ->
]});
db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) ->
+ Location = absolute_uri(Req, "/" ++ ?b2l(Db#db.name) ++ "/" ++ ?b2l(DocId)),
update_doc(Req, Db, DocId, couch_httpd:json_body(Req),
- [{"Location", "/" ++ ?b2l(Db#db.name) ++ "/" ++ ?b2l(DocId)}]);
+ [{"Location", Location}]);
db_doc_req(#httpd{method='COPY'}=Req, Db, SourceDocId) ->
SourceRev =