1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
- import { logger } from 'workbox-core/_private/logger.js';
- import './_version.js';
- const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
- if (process.env.NODE_ENV !== 'production') {
- if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
- throw new WorkboxError('invalid-responses-are-same-args');
- }
- }
- const atLeastOneHeaderAvailable = headersToCheck.some((header) => {
- return (firstResponse.headers.has(header) && secondResponse.headers.has(header));
- });
- if (!atLeastOneHeaderAvailable) {
- if (process.env.NODE_ENV !== 'production') {
- logger.warn(`Unable to determine where the response has been updated ` +
- `because none of the headers that would be checked are present.`);
- logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
- }
-
-
- return true;
- }
- return headersToCheck.every((header) => {
- const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
- const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
- return headerStateComparison && headerValueComparison;
- });
- };
- export { responsesAreSame };
|