couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject git commit: Cache-bust every attachment range GET
Date Sat, 07 Jan 2012 16:05:26 GMT
Updated Branches:
  refs/heads/1.2.x 482234854 -> 0d8ddc808


Cache-bust every attachment range GET

This appears to expose a bug in Chrome for an edge case. There's a
test that sends "Range: bytes=0-29" for an item that is one byte
shorter than the requested range. Curl, Firefox and Safari correctly
returns;

Content-Range: bytes 0-28/29
Content-Length: 29

Whereas Safari erroneously gets this;

Content-Range: bytes 0-29/29
Content-Length: 30

So, this test will fail on Chrome until a) Chrome is fixed or b)
someone points out that I'm wrong about the Chrome bug.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0d8ddc80
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0d8ddc80
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0d8ddc80

Branch: refs/heads/1.2.x
Commit: 0d8ddc8082af4f44f292a7192f1971d4e7c11bb2
Parents: 4822348
Author: Robert Newson <rnewson@apache.org>
Authored: Sat Jan 7 15:57:04 2012 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Sat Jan 7 16:05:06 2012 +0000

----------------------------------------------------------------------
 share/www/script/test/attachment_ranges.js |   30 +++++++++++++----------
 1 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/0d8ddc80/share/www/script/test/attachment_ranges.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/attachment_ranges.js b/share/www/script/test/attachment_ranges.js
index 603848e..a4ea4d3 100644
--- a/share/www/script/test/attachment_ranges.js
+++ b/share/www/script/test/attachment_ranges.js
@@ -9,6 +9,11 @@
 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 // License for the specific language governing permissions and limitations under
 // the License.
+
+function cacheBust() {
+    return "?anti-cache=" + String(Math.round(Math.random() * 1000000));
+};
+
 couchTests.attachment_ranges = function(debug) {
     var db = new CouchDB("test_suite_db", {
         "X-Couch-Full-Commit": "false"
@@ -32,7 +37,7 @@ couchTests.attachment_ranges = function(debug) {
     T(save_response.ok);
 
     // Fetching the whole entity is a 206.
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt?bar=0", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=0-28"
         }
@@ -43,8 +48,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("29", xhr.getResponseHeader("Content-Length"));
 
     // Fetch the whole entity without an end offset is a 200.
-    var rand = "&foo=" + Math.random(10000000);
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt?bar=1" + rand, {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=0-"
         }
@@ -55,7 +59,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("29", xhr.getResponseHeader("Content-Length"));
 
     // Even if you ask multiple times.
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=0-,0-,0-"
         }
@@ -63,7 +67,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals(200, xhr.status, "multiple 0-'s");
 
     // Badly formed range header is a 200.
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes:0-"
         }
@@ -71,7 +75,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals(200, xhr.status, "fetch with bad range header");
 
     // Fetch the end of an entity without an end offset is a 206.
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt"  + cacheBust(), {
         headers: {
             "Range": "bytes=2-"
         }
@@ -82,7 +86,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("27", xhr.getResponseHeader("Content-Length"));
 
     // Fetch past the end of the entity is a 206
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt"  + cacheBust(), {
         headers: {
             "Range": "bytes=0-29"
         }
@@ -92,7 +96,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("29", xhr.getResponseHeader("Content-Length"));
 
     // Fetch first part of entity is a 206
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=0-3"
         }
@@ -103,7 +107,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("bytes 0-3/29", xhr.getResponseHeader("Content-Range"));
 
     // Fetch middle of entity is also a 206
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=10-15"
         }
@@ -114,7 +118,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("bytes 10-15/29", xhr.getResponseHeader("Content-Range"));
 
     // Fetch end of entity is also a 206
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=-3"
         }
@@ -125,7 +129,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals("bytes 26-28/29", xhr.getResponseHeader("Content-Range"));
     
     // backward range is 416
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
        headers: {
            "Range": "bytes=5-3"
        }
@@ -133,7 +137,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals(416, xhr.status, "fetch 5-3");
 
     // range completely outside of entity is 416
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=300-310"
         }
@@ -141,7 +145,7 @@ couchTests.attachment_ranges = function(debug) {
     TEquals(416, xhr.status, "fetch 300-310");
 
     // We ignore a Range header with too many ranges
-    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
+    var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt" + cacheBust(), {
         headers: {
             "Range": "bytes=0-1,0-1,0-1,0-1,0-1,0-1,0-1,0-1,0-1,0-1"
         }


Mime
View raw message