Author: jan
Date: Fri Mar 27 00:26:39 2009
New Revision: 758942

URL: http://svn.apache.org/viewvc?rev=758942&view=rev
Log:
Location header responses should be absolute URIs, thanks Christopher

Modified:
    couchdb/trunk/share/www/script/test/basics.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=758942&r1=758941&r2=758942&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Fri Mar 27 00:26:39 2009
@@ -31,8 +31,13 @@
     // 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 @@
     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);

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=758942&r1=758941&r2=758942&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Mar 27 00:26:39 2009
@@ -56,7 +56,8 @@
     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='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 =


Reply via email to