diff options
author | Robert Newson <rnewson@apache.org> | 2010-08-18 11:41:10 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2010-08-18 11:41:10 +0000 |
commit | d18d7036788acf2d5ddab608d0352158139de189 (patch) | |
tree | 4474cce378e152c36bd4484a673776ab3abe15be /share/www/script | |
parent | 6ddcdf17ef2a5e55f0962211c7c878aa5e74ffe7 (diff) |
COUCHDB-161 - support Range header for attachments.
Attachments are upgraded to support the Range header on compaction.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@986629 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r-- | share/www/script/couch_tests.js | 1 | ||||
-rw-r--r-- | share/www/script/test/attachment_ranges.js | 108 |
2 files changed, 109 insertions, 0 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index c048521c..0b8f9288 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -36,6 +36,7 @@ loadTest("attachments.js"); loadTest("attachments_multipart.js"); loadTest("attachment_names.js"); loadTest("attachment_paths.js"); +loadTest("attachment_ranges.js"); loadTest("attachment_views.js"); loadTest("auth_cache.js"); loadTest("batch_save.js"); diff --git a/share/www/script/test/attachment_ranges.js b/share/www/script/test/attachment_ranges.js new file mode 100644 index 00000000..65c1f475 --- /dev/null +++ b/share/www/script/test/attachment_ranges.js @@ -0,0 +1,108 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +couchTests.attachment_ranges = function(debug) { + var db = new CouchDB("test_suite_db", { + "X-Couch-Full-Commit": "false" + }); + db.deleteDb(); + db.createDb(); + + if (debug) debugger; + + var binAttDoc = { + _id: "bin_doc", + _attachments: { + "foo.txt": { + content_type: "application/octet-stream", + data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" + } + } + } + + var save_response = db.save(binAttDoc); + T(save_response.ok); + + // Fetching the whole entity is a 206. + var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", { + headers: { + "Range": "bytes=0-28" + } + }); + TEquals(206, xhr.status); + TEquals("This is a base64 encoded text", xhr.responseText); + TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range")); + TEquals("29", xhr.getResponseHeader("Content-Length")); + + // Fetch the whole entity without an end offset is a 200. + var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", { + headers: { + "Range": "bytes=0-" + } + }); + TEquals(200, xhr.status); + TEquals("This is a base64 encoded text", xhr.responseText); + TEquals("29", xhr.getResponseHeader("Content-Length")); + + // 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", { + headers: { + "Range": "bytes=2-" + } + }); + TEquals(206, xhr.status); + TEquals("is is a base64 encoded text", xhr.responseText); + TEquals("bytes 2-28/29", xhr.getResponseHeader("Content-Range")); + TEquals("27", xhr.getResponseHeader("Content-Length")); + + // Fetch past the end of the entity is a 416 + var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", { + headers: { + "Range": "bytes=0-29" + } + }); + TEquals(416, xhr.status); + + // Fetch first part of entity is a 206 + var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", { + headers: { + "Range": "bytes=0-3" + } + }); + TEquals(206, xhr.status); + TEquals("This", xhr.responseText); + TEquals("4", xhr.getResponseHeader("Content-Length")); + 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", { + headers: { + "Range": "bytes=10-15" + } + }); + TEquals(206, xhr.status); + TEquals("base64", xhr.responseText); + TEquals("6", xhr.getResponseHeader("Content-Length")); + 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", { + headers: { + "Range": "bytes=-3" + } + }); + TEquals(206, xhr.status); + TEquals("text", xhr.responseText); + TEquals("4", xhr.getResponseHeader("Content-Length")); + TEquals("bytes 25-28/29", xhr.getResponseHeader("Content-Range")); + + +}; |