summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/couch.js2
-rw-r--r--share/www/script/couch_tests.js23
-rw-r--r--src/couchdb/couch_httpd_misc_handlers.erl10
3 files changed, 27 insertions, 8 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index 96612faa..21382dd0 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -312,7 +312,7 @@ CouchDB.newUuids = function(n) {
}
return uuids;
} else {
- CouchDB.last_req = CouchDB.request("POST", "/_uuids?count=" + (100 + n));
+ CouchDB.last_req = CouchDB.request("GET", "/_uuids?count=" + (100 + n));
CouchDB.maybeThrowError(CouchDB.last_req);
var result = JSON.parse(CouchDB.last_req.responseText);
CouchDB.uuids_cache =
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 55a63bc9..e9594918 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -457,20 +457,33 @@ db.createDb();
},
uuids: function(debug) {
+ var testHashBustingHeaders = function(xhr) {
+ T(xhr.getResponseHeader("Cache-Control").match(/no-cache/));
+ T(xhr.getResponseHeader("Pragma") == "no-cache");
+
+ var currentTime = new Date();
+ var expiresHeader = Date.parse(xhr.getResponseHeader("Expires"));
+ var dateHeader = Date.parse(xhr.getResponseHeader("Date"));
+
+ T(expiresHeader < currentTime);
+ T(currentTime - dateHeader < 3000);
+ };
+
var db = new CouchDB("test_suite_db");
db.deleteDb();
db.createDb();
if (debug) debugger;
// a single UUID without an explicit count
- var xhr = CouchDB.request("POST", "/_uuids");
+ var xhr = CouchDB.request("GET", "/_uuids");
T(xhr.status == 200);
var result = JSON.parse(xhr.responseText);
T(result.uuids.length == 1);
var first = result.uuids[0];
+ testHashBustingHeaders(xhr);
// a single UUID with an explicit count
- xhr = CouchDB.request("POST", "/_uuids?count=1");
+ xhr = CouchDB.request("GET", "/_uuids?count=1");
T(xhr.status == 200);
result = JSON.parse(xhr.responseText);
T(result.uuids.length == 1);
@@ -478,7 +491,7 @@ db.createDb();
T(first != second);
// no collisions with 1,000 UUIDs
- xhr = CouchDB.request("POST", "/_uuids?count=1000");
+ xhr = CouchDB.request("GET", "/_uuids?count=1000");
T(xhr.status == 200);
result = JSON.parse(xhr.responseText);
T( result.uuids.length == 1000 );
@@ -489,7 +502,9 @@ db.createDb();
seen[id] = 1;
}
- // check our library
+ // ensure we return a 405 on POST
+ xhr = CouchDB.request("POST", "/_uuids?count=1000");
+ T(xhr.status == 405);
},
bulk_docs: function(debug) {
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
index 71a0e9ae..92ff3b0a 100644
--- a/src/couchdb/couch_httpd_misc_handlers.erl
+++ b/src/couchdb/couch_httpd_misc_handlers.erl
@@ -113,14 +113,18 @@ handle_restart_req(Req) ->
send_method_not_allowed(Req, "POST").
-handle_uuids_req(#httpd{method='POST'}=Req) ->
+handle_uuids_req(#httpd{method='GET'}=Req) ->
Count = list_to_integer(couch_httpd:qs_value(Req, "count", "1")),
+ CacheBustingHeaders = [{"Date", httpd_util:rfc1123_date()},
+ {"Cache-Control", "no-cache"},
+ {"Expires", "Fri, 01 Jan 1990 00:00:00 GMT"}, % Past date, ON PURPOSE!
+ {"Pragma", "no-cache"}],
% generate the uuids
UUIDs = [ couch_util:new_uuid() || _ <- lists:seq(1,Count)],
% send a JSON response
- send_json(Req, {[{<<"uuids">>, UUIDs}]});
+ send_json(Req, 200, CacheBustingHeaders, {[{<<"uuids">>, UUIDs}]});
handle_uuids_req(Req) ->
- send_method_not_allowed(Req, "POST").
+ send_method_not_allowed(Req, "GET").
% Config request handler