couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r743373 - in /couchdb/trunk: share/www/script/couch.js share/www/script/couch_tests.js src/couchdb/couch_httpd_misc_handlers.erl
Date Wed, 11 Feb 2009 16:12:40 GMT
Author: damien
Date: Wed Feb 11 16:12:39 2009
New Revision: 743373

URL: http://svn.apache.org/viewvc?rev=743373&view=rev
Log:
Changed _uuid to respond to GET instead of POST. Bug COUCHDB-190

Modified:
    couchdb/trunk/share/www/script/couch.js
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl

Modified: couchdb/trunk/share/www/script/couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch.js?rev=743373&r1=743372&r2=743373&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch.js [utf-8] Wed Feb 11 16:12:39 2009
@@ -312,7 +312,7 @@
     }
     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 =

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=743373&r1=743372&r2=743373&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Wed Feb 11 16:12:39 2009
@@ -457,20 +457,33 @@
   },
 
   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 @@
     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 @@
       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) {

Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=743373&r1=743372&r2=743373&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Wed Feb 11 16:12:39 2009
@@ -113,14 +113,18 @@
     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



Mime
View raw message