mirror of
https://github.com/idanoo/GoScrobble
synced 2025-07-01 05:32:18 +00:00
0.2.0 - Mid migration
This commit is contained in:
parent
139e6a915e
commit
7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions
19
web/node_modules/workbox-range-requests/LICENSE
generated
vendored
Normal file
19
web/node_modules/workbox-range-requests/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright 2018 Google LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
1
web/node_modules/workbox-range-requests/README.md
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/README.md
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-range-requests
|
26
web/node_modules/workbox-range-requests/RangeRequestsPlugin.d.ts
generated
vendored
Normal file
26
web/node_modules/workbox-range-requests/RangeRequestsPlugin.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { WorkboxPlugin } from 'workbox-core/types.js';
|
||||
import './_version.js';
|
||||
/**
|
||||
* 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 module:workbox-range-requests
|
||||
*/
|
||||
declare class RangeRequestsPlugin implements WorkboxPlugin {
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'];
|
||||
}
|
||||
export { RangeRequestsPlugin };
|
44
web/node_modules/workbox-range-requests/RangeRequestsPlugin.js
generated
vendored
Normal file
44
web/node_modules/workbox-range-requests/RangeRequestsPlugin.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
import { createPartialResponse } from './createPartialResponse.js';
|
||||
import './_version.js';
|
||||
/**
|
||||
* 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 module:workbox-range-requests
|
||||
*/
|
||||
class RangeRequestsPlugin {
|
||||
constructor() {
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
this.cachedResponseWillBeUsed = async ({ 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 { RangeRequestsPlugin };
|
1
web/node_modules/workbox-range-requests/RangeRequestsPlugin.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/RangeRequestsPlugin.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './RangeRequestsPlugin.js';
|
0
web/node_modules/workbox-range-requests/_version.d.ts
generated
vendored
Normal file
0
web/node_modules/workbox-range-requests/_version.d.ts
generated
vendored
Normal file
6
web/node_modules/workbox-range-requests/_version.js
generated
vendored
Normal file
6
web/node_modules/workbox-range-requests/_version.js
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
"use strict";
|
||||
// @ts-ignore
|
||||
try {
|
||||
self['workbox:range-requests:5.1.4'] && _();
|
||||
}
|
||||
catch (e) { }
|
1
web/node_modules/workbox-range-requests/_version.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/_version.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
try{self['workbox:range-requests:5.1.4']&&_()}catch(e){}// eslint-disable-line
|
262
web/node_modules/workbox-range-requests/build/workbox-range-requests.dev.js
generated
vendored
Normal file
262
web/node_modules/workbox-range-requests/build/workbox-range-requests.dev.js
generated
vendored
Normal file
|
@ -0,0 +1,262 @@
|
|||
this.workbox = this.workbox || {};
|
||||
this.workbox.rangeRequests = (function (exports, WorkboxError_js, assert_js, logger_js) {
|
||||
'use strict';
|
||||
|
||||
try {
|
||||
self['workbox:range-requests:5.1.4'] && _();
|
||||
} catch (e) {}
|
||||
|
||||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
/**
|
||||
* @param {Blob} blob A source blob.
|
||||
* @param {number} [start] The offset to use as the start of the
|
||||
* slice.
|
||||
* @param {number} [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) {
|
||||
{
|
||||
assert_js.assert.isInstance(blob, Blob, {
|
||||
moduleName: 'workbox-range-requests',
|
||||
funcName: 'calculateEffectiveBoundaries',
|
||||
paramName: 'blob'
|
||||
});
|
||||
}
|
||||
|
||||
const blobSize = blob.size;
|
||||
|
||||
if (end && end > blobSize || start && start < 0) {
|
||||
throw new WorkboxError_js.WorkboxError('range-not-satisfiable', {
|
||||
size: blobSize,
|
||||
end,
|
||||
start
|
||||
});
|
||||
}
|
||||
|
||||
let effectiveStart;
|
||||
let effectiveEnd;
|
||||
|
||||
if (start !== undefined && end !== undefined) {
|
||||
effectiveStart = start; // Range values are inclusive, so add 1 to the value.
|
||||
|
||||
effectiveEnd = end + 1;
|
||||
} else if (start !== undefined && end === undefined) {
|
||||
effectiveStart = start;
|
||||
effectiveEnd = blobSize;
|
||||
} else if (end !== undefined && start === undefined) {
|
||||
effectiveStart = blobSize - end;
|
||||
effectiveEnd = blobSize;
|
||||
}
|
||||
|
||||
return {
|
||||
start: effectiveStart,
|
||||
end: effectiveEnd
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
/**
|
||||
* @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) {
|
||||
{
|
||||
assert_js.assert.isType(rangeHeader, 'string', {
|
||||
moduleName: 'workbox-range-requests',
|
||||
funcName: 'parseRangeHeader',
|
||||
paramName: 'rangeHeader'
|
||||
});
|
||||
}
|
||||
|
||||
const normalizedRangeHeader = rangeHeader.trim().toLowerCase();
|
||||
|
||||
if (!normalizedRangeHeader.startsWith('bytes=')) {
|
||||
throw new WorkboxError_js.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_js.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 || !(rangeParts[1] || rangeParts[2])) {
|
||||
throw new WorkboxError_js.WorkboxError('invalid-range-values', {
|
||||
normalizedRangeHeader
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),
|
||||
end: rangeParts[2] === '' ? undefined : Number(rangeParts[2])
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
/**
|
||||
* Given a `Request` and `Response` objects as input, this will return a
|
||||
* promise for a new `Response`.
|
||||
*
|
||||
* If the original `Response` already contains partial content (i.e. it has
|
||||
* a status of 206), then this assumes it already fulfills the `Range:`
|
||||
* requirements, and will return it as-is.
|
||||
*
|
||||
* @param {Request} request A request, which should contain a Range:
|
||||
* header.
|
||||
* @param {Response} originalResponse A response.
|
||||
* @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 module:workbox-range-requests
|
||||
*/
|
||||
|
||||
async function createPartialResponse(request, originalResponse) {
|
||||
try {
|
||||
if ("dev" !== 'production') {
|
||||
assert_js.assert.isInstance(request, Request, {
|
||||
moduleName: 'workbox-range-requests',
|
||||
funcName: 'createPartialResponse',
|
||||
paramName: 'request'
|
||||
});
|
||||
assert_js.assert.isInstance(originalResponse, Response, {
|
||||
moduleName: 'workbox-range-requests',
|
||||
funcName: 'createPartialResponse',
|
||||
paramName: 'originalResponse'
|
||||
});
|
||||
}
|
||||
|
||||
if (originalResponse.status === 206) {
|
||||
// If we already have a 206, then just pass it through as-is;
|
||||
// see https://github.com/GoogleChrome/workbox/issues/1720
|
||||
return originalResponse;
|
||||
}
|
||||
|
||||
const rangeHeader = request.headers.get('range');
|
||||
|
||||
if (!rangeHeader) {
|
||||
throw new WorkboxError_js.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', String(slicedBlobSize));
|
||||
slicedResponse.headers.set('Content-Range', `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` + originalBlob.size);
|
||||
return slicedResponse;
|
||||
} catch (error) {
|
||||
{
|
||||
logger_js.logger.warn(`Unable to construct a partial response; returning a ` + `416 Range Not Satisfiable response instead.`);
|
||||
logger_js.logger.groupCollapsed(`View details here.`);
|
||||
logger_js.logger.log(error);
|
||||
logger_js.logger.log(request);
|
||||
logger_js.logger.log(originalResponse);
|
||||
logger_js.logger.groupEnd();
|
||||
}
|
||||
|
||||
return new Response('', {
|
||||
status: 416,
|
||||
statusText: 'Range Not Satisfiable'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
/**
|
||||
* 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 module:workbox-range-requests
|
||||
*/
|
||||
|
||||
class RangeRequestsPlugin {
|
||||
constructor() {
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
this.cachedResponseWillBeUsed = async ({
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.RangeRequestsPlugin = RangeRequestsPlugin;
|
||||
exports.createPartialResponse = createPartialResponse;
|
||||
|
||||
return exports;
|
||||
|
||||
}({}, workbox.core._private, workbox.core._private, workbox.core._private));
|
||||
//# sourceMappingURL=workbox-range-requests.dev.js.map
|
1
web/node_modules/workbox-range-requests/build/workbox-range-requests.dev.js.map
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/build/workbox-range-requests.dev.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
web/node_modules/workbox-range-requests/build/workbox-range-requests.prod.js
generated
vendored
Normal file
2
web/node_modules/workbox-range-requests/build/workbox-range-requests.prod.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
this.workbox=this.workbox||{},this.workbox.rangeRequests=function(t,e,n){"use strict";try{self["workbox:range-requests:5.1.4"]&&_()}catch(t){}async function r(t,n){try{if(206===n.status)return n;const r=t.headers.get("range");if(!r)throw new e.WorkboxError("no-range-header");const s=function(t){const n=t.trim().toLowerCase();if(!n.startsWith("bytes="))throw new e.WorkboxError("unit-must-be-bytes",{normalizedRangeHeader:n});if(n.includes(","))throw new e.WorkboxError("single-range-only",{normalizedRangeHeader:n});const r=/(\d*)-(\d*)/.exec(n);if(!r||!r[1]&&!r[2])throw new e.WorkboxError("invalid-range-values",{normalizedRangeHeader:n});return{start:""===r[1]?void 0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}}(r),a=await n.blob(),o=function(t,n,r){const s=t.size;if(r&&r>s||n&&n<0)throw new e.WorkboxError("range-not-satisfiable",{size:s,end:r,start:n});let a,o;return void 0!==n&&void 0!==r?(a=n,o=r+1):void 0!==n&&void 0===r?(a=n,o=s):void 0!==r&&void 0===n&&(a=s-r,o=s),{start:a,end:o}}(a,s.start,s.end),i=a.slice(o.start,o.end),d=i.size,u=new Response(i,{status:206,statusText:"Partial Content",headers:n.headers});return u.headers.set("Content-Length",String(d)),u.headers.set("Content-Range",`bytes ${o.start}-${o.end-1}/`+a.size),u}catch(t){return new Response("",{status:416,statusText:"Range Not Satisfiable"})}}return t.RangeRequestsPlugin=class{constructor(){this.cachedResponseWillBeUsed=async({request:t,cachedResponse:e})=>e&&t.headers.has("range")?await r(t,e):e}},t.createPartialResponse=r,t}({},workbox.core._private,workbox.core._private);
|
||||
//# sourceMappingURL=workbox-range-requests.prod.js.map
|
1
web/node_modules/workbox-range-requests/build/workbox-range-requests.prod.js.map
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/build/workbox-range-requests.prod.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
21
web/node_modules/workbox-range-requests/createPartialResponse.d.ts
generated
vendored
Normal file
21
web/node_modules/workbox-range-requests/createPartialResponse.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
import './_version.js';
|
||||
/**
|
||||
* Given a `Request` and `Response` objects as input, this will return a
|
||||
* promise for a new `Response`.
|
||||
*
|
||||
* If the original `Response` already contains partial content (i.e. it has
|
||||
* a status of 206), then this assumes it already fulfills the `Range:`
|
||||
* requirements, and will return it as-is.
|
||||
*
|
||||
* @param {Request} request A request, which should contain a Range:
|
||||
* header.
|
||||
* @param {Response} originalResponse A response.
|
||||
* @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 module:workbox-range-requests
|
||||
*/
|
||||
declare function createPartialResponse(request: Request, originalResponse: Response): Promise<Response>;
|
||||
export { createPartialResponse };
|
88
web/node_modules/workbox-range-requests/createPartialResponse.js
generated
vendored
Normal file
88
web/node_modules/workbox-range-requests/createPartialResponse.js
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
|
||||
import { assert } from 'workbox-core/_private/assert.js';
|
||||
import { logger } from 'workbox-core/_private/logger.js';
|
||||
import { calculateEffectiveBoundaries } from './utils/calculateEffectiveBoundaries.js';
|
||||
import { parseRangeHeader } from './utils/parseRangeHeader.js';
|
||||
import './_version.js';
|
||||
/**
|
||||
* Given a `Request` and `Response` objects as input, this will return a
|
||||
* promise for a new `Response`.
|
||||
*
|
||||
* If the original `Response` already contains partial content (i.e. it has
|
||||
* a status of 206), then this assumes it already fulfills the `Range:`
|
||||
* requirements, and will return it as-is.
|
||||
*
|
||||
* @param {Request} request A request, which should contain a Range:
|
||||
* header.
|
||||
* @param {Response} originalResponse A response.
|
||||
* @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 module:workbox-range-requests
|
||||
*/
|
||||
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',
|
||||
});
|
||||
}
|
||||
if (originalResponse.status === 206) {
|
||||
// If we already have a 206, then just pass it through as-is;
|
||||
// see https://github.com/GoogleChrome/workbox/issues/1720
|
||||
return 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', String(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.log(error);
|
||||
logger.log(request);
|
||||
logger.log(originalResponse);
|
||||
logger.groupEnd();
|
||||
}
|
||||
return new Response('', {
|
||||
status: 416,
|
||||
statusText: 'Range Not Satisfiable',
|
||||
});
|
||||
}
|
||||
}
|
||||
export { createPartialResponse };
|
1
web/node_modules/workbox-range-requests/createPartialResponse.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/createPartialResponse.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './createPartialResponse.js';
|
7
web/node_modules/workbox-range-requests/index.d.ts
generated
vendored
Normal file
7
web/node_modules/workbox-range-requests/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { createPartialResponse } from './createPartialResponse.js';
|
||||
import { RangeRequestsPlugin } from './RangeRequestsPlugin.js';
|
||||
import './_version.js';
|
||||
/**
|
||||
* @module workbox-range-requests
|
||||
*/
|
||||
export { createPartialResponse, RangeRequestsPlugin, };
|
14
web/node_modules/workbox-range-requests/index.js
generated
vendored
Normal file
14
web/node_modules/workbox-range-requests/index.js
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
import { createPartialResponse } from './createPartialResponse.js';
|
||||
import { RangeRequestsPlugin } from './RangeRequestsPlugin.js';
|
||||
import './_version.js';
|
||||
/**
|
||||
* @module workbox-range-requests
|
||||
*/
|
||||
export { createPartialResponse, RangeRequestsPlugin, };
|
1
web/node_modules/workbox-range-requests/index.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/index.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './index.js';
|
37
web/node_modules/workbox-range-requests/package.json
generated
vendored
Executable file
37
web/node_modules/workbox-range-requests/package.json
generated
vendored
Executable file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "workbox-range-requests",
|
||||
"version": "5.1.4",
|
||||
"license": "MIT",
|
||||
"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",
|
||||
"workbox-plugin"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "gulp build-packages --package workbox-range-requests",
|
||||
"version": "npm run build",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"workbox": {
|
||||
"browserNamespace": "workbox.rangeRequests",
|
||||
"packageType": "browser"
|
||||
},
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"types": "index.d.ts",
|
||||
"dependencies": {
|
||||
"workbox-core": "^5.1.4"
|
||||
},
|
||||
"gitHead": "a95b6fd489c2a66574f1655b2de3acd2ece35fb3"
|
||||
}
|
49
web/node_modules/workbox-range-requests/src/RangeRequestsPlugin.ts
generated
vendored
Normal file
49
web/node_modules/workbox-range-requests/src/RangeRequestsPlugin.ts
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
import {WorkboxPlugin} from 'workbox-core/types.js';
|
||||
import {createPartialResponse} from './createPartialResponse.js';
|
||||
import './_version.js';
|
||||
|
||||
|
||||
/**
|
||||
* 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 module:workbox-range-requests
|
||||
*/
|
||||
class RangeRequestsPlugin implements WorkboxPlugin {
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'] =
|
||||
async ({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 {RangeRequestsPlugin};
|
2
web/node_modules/workbox-range-requests/src/_version.ts
generated
vendored
Normal file
2
web/node_modules/workbox-range-requests/src/_version.ts
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// @ts-ignore
|
||||
try{self['workbox:range-requests:5.1.4']&&_()}catch(e){}
|
104
web/node_modules/workbox-range-requests/src/createPartialResponse.ts
generated
vendored
Normal file
104
web/node_modules/workbox-range-requests/src/createPartialResponse.ts
generated
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
import {WorkboxError} from 'workbox-core/_private/WorkboxError.js';
|
||||
import {assert} from 'workbox-core/_private/assert.js';
|
||||
import {logger} from 'workbox-core/_private/logger.js';
|
||||
import {calculateEffectiveBoundaries} from './utils/calculateEffectiveBoundaries.js';
|
||||
import {parseRangeHeader} from './utils/parseRangeHeader.js';
|
||||
import './_version.js';
|
||||
|
||||
/**
|
||||
* Given a `Request` and `Response` objects as input, this will return a
|
||||
* promise for a new `Response`.
|
||||
*
|
||||
* If the original `Response` already contains partial content (i.e. it has
|
||||
* a status of 206), then this assumes it already fulfills the `Range:`
|
||||
* requirements, and will return it as-is.
|
||||
*
|
||||
* @param {Request} request A request, which should contain a Range:
|
||||
* header.
|
||||
* @param {Response} originalResponse A response.
|
||||
* @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 module:workbox-range-requests
|
||||
*/
|
||||
async function createPartialResponse(
|
||||
request: Request, originalResponse: Response): Promise<Response> {
|
||||
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',
|
||||
});
|
||||
}
|
||||
|
||||
if (originalResponse.status === 206) {
|
||||
// If we already have a 206, then just pass it through as-is;
|
||||
// see https://github.com/GoogleChrome/workbox/issues/1720
|
||||
return 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', String(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.log(error);
|
||||
logger.log(request);
|
||||
logger.log(originalResponse);
|
||||
logger.groupEnd();
|
||||
}
|
||||
|
||||
return new Response('', {
|
||||
status: 416,
|
||||
statusText: 'Range Not Satisfiable',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export {createPartialResponse};
|
21
web/node_modules/workbox-range-requests/src/index.ts
generated
vendored
Normal file
21
web/node_modules/workbox-range-requests/src/index.ts
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
import {createPartialResponse} from './createPartialResponse.js';
|
||||
import {RangeRequestsPlugin} from './RangeRequestsPlugin.js';
|
||||
import './_version.js';
|
||||
|
||||
|
||||
/**
|
||||
* @module workbox-range-requests
|
||||
*/
|
||||
|
||||
export {
|
||||
createPartialResponse,
|
||||
RangeRequestsPlugin,
|
||||
};
|
65
web/node_modules/workbox-range-requests/src/utils/calculateEffectiveBoundaries.ts
generated
vendored
Normal file
65
web/node_modules/workbox-range-requests/src/utils/calculateEffectiveBoundaries.ts
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
import {WorkboxError} from 'workbox-core/_private/WorkboxError.js';
|
||||
import {assert} from 'workbox-core/_private/assert.js';
|
||||
import '../_version.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {Blob} blob A source blob.
|
||||
* @param {number} [start] The offset to use as the start of the
|
||||
* slice.
|
||||
* @param {number} [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: Blob, start?: number, end?: number): {start: number; end: number} {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
assert!.isInstance(blob, Blob, {
|
||||
moduleName: 'workbox-range-requests',
|
||||
funcName: 'calculateEffectiveBoundaries',
|
||||
paramName: 'blob',
|
||||
});
|
||||
}
|
||||
|
||||
const blobSize = blob.size;
|
||||
|
||||
if ((end && end > blobSize) || (start && start < 0)) {
|
||||
throw new WorkboxError('range-not-satisfiable', {
|
||||
size: blobSize,
|
||||
end,
|
||||
start,
|
||||
});
|
||||
}
|
||||
|
||||
let effectiveStart: number;
|
||||
let effectiveEnd: number;
|
||||
|
||||
if (start !== undefined && end !== undefined) {
|
||||
effectiveStart = start;
|
||||
// Range values are inclusive, so add 1 to the value.
|
||||
effectiveEnd = end + 1;
|
||||
} else if (start !== undefined && end === undefined) {
|
||||
effectiveStart = start;
|
||||
effectiveEnd = blobSize;
|
||||
} else if (end !== undefined && start === undefined) {
|
||||
effectiveStart = blobSize - end;
|
||||
effectiveEnd = blobSize;
|
||||
}
|
||||
|
||||
return {
|
||||
start: effectiveStart!,
|
||||
end: effectiveEnd!,
|
||||
};
|
||||
}
|
||||
|
||||
export {calculateEffectiveBoundaries};
|
55
web/node_modules/workbox-range-requests/src/utils/parseRangeHeader.ts
generated
vendored
Normal file
55
web/node_modules/workbox-range-requests/src/utils/parseRangeHeader.ts
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
|
||||
import {WorkboxError} from 'workbox-core/_private/WorkboxError.js';
|
||||
import {assert} from 'workbox-core/_private/assert.js';
|
||||
import '../_version.js';
|
||||
|
||||
|
||||
/**
|
||||
* @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: string): {start?: number; end?: number} {
|
||||
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 || !(rangeParts[1] || rangeParts[2])) {
|
||||
throw new WorkboxError('invalid-range-values', {normalizedRangeHeader});
|
||||
}
|
||||
|
||||
return {
|
||||
start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),
|
||||
end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),
|
||||
};
|
||||
}
|
||||
|
||||
export {parseRangeHeader};
|
14
web/node_modules/workbox-range-requests/tsconfig.json
generated
vendored
Normal file
14
web/node_modules/workbox-range-requests/tsconfig.json
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "./",
|
||||
"rootDir": "./src",
|
||||
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../workbox-core/" }
|
||||
]
|
||||
}
|
2454
web/node_modules/workbox-range-requests/tsconfig.tsbuildinfo
generated
vendored
Normal file
2454
web/node_modules/workbox-range-requests/tsconfig.tsbuildinfo
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
16
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.d.ts
generated
vendored
Normal file
16
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import '../_version.js';
|
||||
/**
|
||||
* @param {Blob} blob A source blob.
|
||||
* @param {number} [start] The offset to use as the start of the
|
||||
* slice.
|
||||
* @param {number} [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
|
||||
*/
|
||||
declare function calculateEffectiveBoundaries(blob: Blob, start?: number, end?: number): {
|
||||
start: number;
|
||||
end: number;
|
||||
};
|
||||
export { calculateEffectiveBoundaries };
|
57
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.js
generated
vendored
Normal file
57
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.js
generated
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
|
||||
import { assert } from 'workbox-core/_private/assert.js';
|
||||
import '../_version.js';
|
||||
/**
|
||||
* @param {Blob} blob A source blob.
|
||||
* @param {number} [start] The offset to use as the start of the
|
||||
* slice.
|
||||
* @param {number} [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 && end > blobSize) || (start && start < 0)) {
|
||||
throw new WorkboxError('range-not-satisfiable', {
|
||||
size: blobSize,
|
||||
end,
|
||||
start,
|
||||
});
|
||||
}
|
||||
let effectiveStart;
|
||||
let effectiveEnd;
|
||||
if (start !== undefined && end !== undefined) {
|
||||
effectiveStart = start;
|
||||
// Range values are inclusive, so add 1 to the value.
|
||||
effectiveEnd = end + 1;
|
||||
}
|
||||
else if (start !== undefined && end === undefined) {
|
||||
effectiveStart = start;
|
||||
effectiveEnd = blobSize;
|
||||
}
|
||||
else if (end !== undefined && start === undefined) {
|
||||
effectiveStart = blobSize - end;
|
||||
effectiveEnd = blobSize;
|
||||
}
|
||||
return {
|
||||
start: effectiveStart,
|
||||
end: effectiveEnd,
|
||||
};
|
||||
}
|
||||
export { calculateEffectiveBoundaries };
|
1
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/utils/calculateEffectiveBoundaries.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './calculateEffectiveBoundaries.js';
|
14
web/node_modules/workbox-range-requests/utils/parseRangeHeader.d.ts
generated
vendored
Normal file
14
web/node_modules/workbox-range-requests/utils/parseRangeHeader.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
import '../_version.js';
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare function parseRangeHeader(rangeHeader: string): {
|
||||
start?: number;
|
||||
end?: number;
|
||||
};
|
||||
export { parseRangeHeader };
|
47
web/node_modules/workbox-range-requests/utils/parseRangeHeader.js
generated
vendored
Normal file
47
web/node_modules/workbox-range-requests/utils/parseRangeHeader.js
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright 2018 Google LLC
|
||||
|
||||
Use of this source code is governed by an MIT-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
|
||||
import { assert } from 'workbox-core/_private/assert.js';
|
||||
import '../_version.js';
|
||||
/**
|
||||
* @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 || !(rangeParts[1] || rangeParts[2])) {
|
||||
throw new WorkboxError('invalid-range-values', { normalizedRangeHeader });
|
||||
}
|
||||
return {
|
||||
start: rangeParts[1] === '' ? undefined : Number(rangeParts[1]),
|
||||
end: rangeParts[2] === '' ? undefined : Number(rangeParts[2]),
|
||||
};
|
||||
}
|
||||
export { parseRangeHeader };
|
1
web/node_modules/workbox-range-requests/utils/parseRangeHeader.mjs
generated
vendored
Normal file
1
web/node_modules/workbox-range-requests/utils/parseRangeHeader.mjs
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './parseRangeHeader.js';
|
Loading…
Add table
Add a link
Reference in a new issue