aboutsummaryrefslogtreecommitdiff
path: root/node_modules/workbox-range-requests
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/workbox-range-requests
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/workbox-range-requests')
-rw-r--r--node_modules/workbox-range-requests/Plugin.mjs52
-rw-r--r--node_modules/workbox-range-requests/README.md1
-rw-r--r--node_modules/workbox-range-requests/_public.mjs24
-rw-r--r--node_modules/workbox-range-requests/_version.mjs1
-rw-r--r--node_modules/workbox-range-requests/browser.mjs19
-rw-r--r--node_modules/workbox-range-requests/createPartialResponse.mjs105
-rw-r--r--node_modules/workbox-range-requests/index.mjs23
-rwxr-xr-xnode_modules/workbox-range-requests/package.json34
-rw-r--r--node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs72
-rw-r--r--node_modules/workbox-range-requests/utils/parseRangeHeader.mjs63
10 files changed, 394 insertions, 0 deletions
diff --git a/node_modules/workbox-range-requests/Plugin.mjs b/node_modules/workbox-range-requests/Plugin.mjs
new file mode 100644
index 00000000..2fac2aea
--- /dev/null
+++ b/node_modules/workbox-range-requests/Plugin.mjs
@@ -0,0 +1,52 @@
+/*
+ Copyright 2016 Google Inc. All Rights Reserved.
+ 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.
+*/
+
+import {createPartialResponse} from './createPartialResponse.mjs';
+
+import './_version.mjs';
+
+/**
+ * The range request plugin makes it easy for a request with a 'Range' header to
+ * be fulfilled by a cached response.
+ *
+ * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback
+ * and returning the appropriate subset of the cached response body.
+ *
+ * @memberof workbox.rangeRequests
+ */
+class Plugin {
+ /**
+ * @param {Object} options
+ * @param {Request} options.request The original request, which may or may not
+ * contain a Range: header.
+ * @param {Response} options.cachedResponse The complete cached response.
+ * @return {Promise<Response>} If request contains a 'Range' header, then a
+ * new response with status 206 whose body is a subset of `cachedResponse` is
+ * returned. Otherwise, `cachedResponse` is returned as-is.
+ *
+ * @private
+ */
+ async cachedResponseWillBeUsed({request, cachedResponse}) {
+ // Only return a sliced response if there's something valid in the cache,
+ // and there's a Range: header in the request.
+ if (cachedResponse && request.headers.has('range')) {
+ return await createPartialResponse(request, cachedResponse);
+ }
+
+ // If there was no Range: header, or if cachedResponse wasn't valid, just
+ // pass it through as-is.
+ return cachedResponse;
+ }
+}
+
+export {Plugin};
diff --git a/node_modules/workbox-range-requests/README.md b/node_modules/workbox-range-requests/README.md
new file mode 100644
index 00000000..ac4afc6f
--- /dev/null
+++ b/node_modules/workbox-range-requests/README.md
@@ -0,0 +1 @@
+This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-range-requests
diff --git a/node_modules/workbox-range-requests/_public.mjs b/node_modules/workbox-range-requests/_public.mjs
new file mode 100644
index 00000000..a3340ac9
--- /dev/null
+++ b/node_modules/workbox-range-requests/_public.mjs
@@ -0,0 +1,24 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+import {createPartialResponse} from './createPartialResponse.mjs';
+import {Plugin} from './Plugin.mjs';
+import './_version.mjs';
+
+export {
+ createPartialResponse,
+ Plugin,
+};
diff --git a/node_modules/workbox-range-requests/_version.mjs b/node_modules/workbox-range-requests/_version.mjs
new file mode 100644
index 00000000..2e51baa1
--- /dev/null
+++ b/node_modules/workbox-range-requests/_version.mjs
@@ -0,0 +1 @@
+try{self.workbox.v['workbox:range-requests:3.6.3']=1;}catch(e){} // eslint-disable-line \ No newline at end of file
diff --git a/node_modules/workbox-range-requests/browser.mjs b/node_modules/workbox-range-requests/browser.mjs
new file mode 100644
index 00000000..e3caf3d8
--- /dev/null
+++ b/node_modules/workbox-range-requests/browser.mjs
@@ -0,0 +1,19 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+import './_version.mjs';
+
+export * from './_public.mjs';
diff --git a/node_modules/workbox-range-requests/createPartialResponse.mjs b/node_modules/workbox-range-requests/createPartialResponse.mjs
new file mode 100644
index 00000000..b8cdb462
--- /dev/null
+++ b/node_modules/workbox-range-requests/createPartialResponse.mjs
@@ -0,0 +1,105 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+import {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';
+import {assert} from 'workbox-core/_private/assert.mjs';
+import {logger} from 'workbox-core/_private/logger.mjs';
+
+import {calculateEffectiveBoundaries} from
+ './utils/calculateEffectiveBoundaries.mjs';
+import {parseRangeHeader} from './utils/parseRangeHeader.mjs';
+
+import './_version.mjs';
+
+/**
+ * Given a `Request` and `Response` objects as input, this will return a
+ * promise for a new `Response`.
+ *
+ * @param {Request} request A request, which should contain a Range:
+ * header.
+ * @param {Response} originalResponse An original response containing the full
+ * content.
+ * @return {Promise<Response>} Either a `206 Partial Content` response, with
+ * the response body set to the slice of content specified by the request's
+ * `Range:` header, or a `416 Range Not Satisfiable` response if the
+ * conditions of the `Range:` header can't be met.
+ *
+ * @memberof workbox.rangeRequests
+ */
+async function createPartialResponse(request, originalResponse) {
+ try {
+ if (process.env.NODE_ENV !== 'production') {
+ assert.isInstance(request, Request, {
+ moduleName: 'workbox-range-requests',
+ funcName: 'createPartialResponse',
+ paramName: 'request',
+ });
+
+ assert.isInstance(originalResponse, Response, {
+ moduleName: 'workbox-range-requests',
+ funcName: 'createPartialResponse',
+ paramName: 'originalResponse',
+ });
+ }
+
+ const rangeHeader = request.headers.get('range');
+ if (!rangeHeader) {
+ throw new WorkboxError('no-range-header');
+ }
+
+ const boundaries = parseRangeHeader(rangeHeader);
+ const originalBlob = await originalResponse.blob();
+
+ const effectiveBoundaries = calculateEffectiveBoundaries(
+ originalBlob, boundaries.start, boundaries.end);
+
+ const slicedBlob = originalBlob.slice(effectiveBoundaries.start,
+ effectiveBoundaries.end);
+ const slicedBlobSize = slicedBlob.size;
+
+ const slicedResponse = new Response(slicedBlob, {
+ // Status code 206 is for a Partial Content response.
+ // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206
+ status: 206,
+ statusText: 'Partial Content',
+ headers: originalResponse.headers,
+ });
+
+ slicedResponse.headers.set('Content-Length', slicedBlobSize);
+ slicedResponse.headers.set('Content-Range',
+ `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +
+ originalBlob.size);
+
+ return slicedResponse;
+ } catch (error) {
+ if (process.env.NODE_ENV !== 'production') {
+ logger.warn(`Unable to construct a partial response; returning a ` +
+ `416 Range Not Satisfiable response instead.`);
+ logger.groupCollapsed(`View details here.`);
+ logger.unprefixed.log(error);
+ logger.unprefixed.log(request);
+ logger.unprefixed.log(originalResponse);
+ logger.groupEnd();
+ }
+
+ return new Response('', {
+ status: 416,
+ statusText: 'Range Not Satisfiable',
+ });
+ }
+}
+
+export {createPartialResponse};
diff --git a/node_modules/workbox-range-requests/index.mjs b/node_modules/workbox-range-requests/index.mjs
new file mode 100644
index 00000000..bbf4aefe
--- /dev/null
+++ b/node_modules/workbox-range-requests/index.mjs
@@ -0,0 +1,23 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+/**
+ * @namespace workbox.rangeRequests
+ */
+
+import './_version.mjs';
+
+export * from './_public.mjs';
diff --git a/node_modules/workbox-range-requests/package.json b/node_modules/workbox-range-requests/package.json
new file mode 100755
index 00000000..0d25ad2e
--- /dev/null
+++ b/node_modules/workbox-range-requests/package.json
@@ -0,0 +1,34 @@
+{
+ "name": "workbox-range-requests",
+ "version": "3.6.3",
+ "license": "Apache-2.0",
+ "author": "Google's Web DevRel Team",
+ "description": "This library creates a new Response, given a source Response and a Range header value.",
+ "repository": "googlechrome/workbox",
+ "bugs": "https://github.com/googlechrome/workbox/issues",
+ "homepage": "https://github.com/GoogleChrome/workbox",
+ "keywords": [
+ "workbox",
+ "workboxjs",
+ "service worker",
+ "sw",
+ "caching",
+ "cache",
+ "range",
+ "media"
+ ],
+ "scripts": {
+ "build": "gulp build-packages --package workbox-range-requests",
+ "version": "npm run build",
+ "prepare": "npm run build"
+ },
+ "workbox": {
+ "browserNamespace": "workbox.rangeRequests",
+ "packageType": "browser"
+ },
+ "main": "build/workbox-range-requests.prod.js",
+ "module": "index.mjs",
+ "dependencies": {
+ "workbox-core": "^3.6.3"
+ }
+}
diff --git a/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs b/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs
new file mode 100644
index 00000000..84c4e187
--- /dev/null
+++ b/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs
@@ -0,0 +1,72 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+import {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';
+import {assert} from 'workbox-core/_private/assert.mjs';
+
+import '../_version.mjs';
+
+/**
+ * @param {Blob} blob A source blob.
+ * @param {number|null} start The offset to use as the start of the
+ * slice.
+ * @param {number|null} end The offset to use as the end of the slice.
+ * @return {Object} An object with `start` and `end` properties, reflecting
+ * the effective boundaries to use given the size of the blob.
+ *
+ * @private
+ */
+function calculateEffectiveBoundaries(blob, start, end) {
+ if (process.env.NODE_ENV !== 'production') {
+ assert.isInstance(blob, Blob, {
+ moduleName: 'workbox-range-requests',
+ funcName: 'calculateEffectiveBoundaries',
+ paramName: 'blob',
+ });
+ }
+
+ const blobSize = blob.size;
+
+ if (end > blobSize || start < 0) {
+ throw new WorkboxError('range-not-satisfiable', {
+ size: blobSize,
+ end,
+ start,
+ });
+ }
+
+ let effectiveStart;
+ let effectiveEnd;
+
+ if (start === null) {
+ effectiveStart = blobSize - end;
+ effectiveEnd = blobSize;
+ } else if (end === null) {
+ effectiveStart = start;
+ effectiveEnd = blobSize;
+ } else {
+ effectiveStart = start;
+ // Range values are inclusive, so add 1 to the value.
+ effectiveEnd = end + 1;
+ }
+
+ return {
+ start: effectiveStart,
+ end: effectiveEnd,
+ };
+}
+
+export {calculateEffectiveBoundaries};
diff --git a/node_modules/workbox-range-requests/utils/parseRangeHeader.mjs b/node_modules/workbox-range-requests/utils/parseRangeHeader.mjs
new file mode 100644
index 00000000..3ad46c3b
--- /dev/null
+++ b/node_modules/workbox-range-requests/utils/parseRangeHeader.mjs
@@ -0,0 +1,63 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ https://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.
+*/
+
+import {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';
+import {assert} from 'workbox-core/_private/assert.mjs';
+
+import '../_version.mjs';
+
+/**
+ * @param {string} rangeHeader A Range: header value.
+ * @return {Object} An object with `start` and `end` properties, reflecting
+ * the parsed value of the Range: header. If either the `start` or `end` are
+ * omitted, then `null` will be returned.
+ *
+ * @private
+ */
+function parseRangeHeader(rangeHeader) {
+ if (process.env.NODE_ENV !== 'production') {
+ assert.isType(rangeHeader, 'string', {
+ moduleName: 'workbox-range-requests',
+ funcName: 'parseRangeHeader',
+ paramName: 'rangeHeader',
+ });
+ }
+
+ const normalizedRangeHeader = rangeHeader.trim().toLowerCase();
+ if (!normalizedRangeHeader.startsWith('bytes=')) {
+ throw new WorkboxError('unit-must-be-bytes', {normalizedRangeHeader});
+ }
+
+ // Specifying multiple ranges separate by commas is valid syntax, but this
+ // library only attempts to handle a single, contiguous sequence of bytes.
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#Syntax
+ if (normalizedRangeHeader.includes(',')) {
+ throw new WorkboxError('single-range-only', {normalizedRangeHeader});
+ }
+
+ const rangeParts = /(\d*)-(\d*)/.exec(normalizedRangeHeader);
+ // We need either at least one of the start or end values.
+ if (rangeParts === null || !(rangeParts[1] || rangeParts[2])) {
+ throw new WorkboxError('invalid-range-values', {normalizedRangeHeader});
+ }
+
+ return {
+ start: rangeParts[1] === '' ? null : Number(rangeParts[1]),
+ end: rangeParts[2] === '' ? null : Number(rangeParts[2]),
+ };
+}
+
+export {parseRangeHeader};