summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2012-01-07 15:57:04 +0000
committerRobert Newson <rnewson@apache.org>2012-01-07 15:57:04 +0000
commit6f774bc0e73fbd805384acbb98c9a89d84793f8e (patch)
treed5b2cae4fb771ecdaaf370b2c4ec3ebc58c4e3a5
parent07c78bf417e5ae1a8e6f457a48605a0d6b2dd248 (diff)
downloadcouchdb-6f774bc0e73fbd805384acbb98c9a89d84793f8e.tar.gz
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.
-rw-r--r--share/www/script/test/attachment_ranges.js30
1 files changed, 17 insertions, 13 deletions
diff --git a/share/www/script/test/attachment_ranges.js b/share/www/script/test/attachment_ranges.js
index 603848e54..a4ea4d322 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"
}