From 5e71b8138b2cd722e271e950786fdb5942573b8d Mon Sep 17 00:00:00 2001 From: David Reed Date: Fri, 18 Nov 2022 20:28:50 -0500 Subject: [PATCH] separate consts --- src/uv.sw.js | 58 +++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/src/uv.sw.js b/src/uv.sw.js index 013c4c9..2f89af4 100644 --- a/src/uv.sw.js +++ b/src/uv.sw.js @@ -10,6 +10,27 @@ */ const Ultraviolet = globalThis.Ultraviolet; +const cspHeaders = [ + 'cross-origin-embedder-policy', + 'cross-origin-opener-policy', + 'cross-origin-resource-policy', + 'content-security-policy', + 'content-security-policy-report-only', + 'expect-ct', + 'feature-policy', + 'origin-isolation', + 'strict-transport-security', + 'upgrade-insecure-requests', + 'x-content-type-options', + 'x-download-options', + 'x-frame-options', + 'x-permitted-cross-domain-policies', + 'x-powered-by', + 'x-xss-protection', +]; +const emptyMethods = ['GET', 'HEAD']; +const emptyStatus = [204, 304]; + class UVServiceWorker extends EventEmitter { constructor(config = __uv$config) { super(); @@ -19,33 +40,6 @@ class UVServiceWorker extends EventEmitter { typeof config.bare === 'string' ? [new URL(config.bare, location)] : config.bare.map((str) => new URL(str, location)); - this.headers = { - csp: [ - 'cross-origin-embedder-policy', - 'cross-origin-opener-policy', - 'cross-origin-resource-policy', - 'content-security-policy', - 'content-security-policy-report-only', - 'expect-ct', - 'feature-policy', - 'origin-isolation', - 'strict-transport-security', - 'upgrade-insecure-requests', - 'x-content-type-options', - 'x-download-options', - 'x-frame-options', - 'x-permitted-cross-domain-policies', - 'x-powered-by', - 'x-xss-protection', - ], - forward: ['accept-encoding', 'connection', 'content-length'], - }; - this.method = { - empty: ['GET', 'HEAD'], - }; - this.statusCode = { - empty: [204, 304], - }; this.config = config; /** * @type {InstanceType} @@ -56,11 +50,6 @@ class UVServiceWorker extends EventEmitter { this.browser = Ultraviolet.Bowser.getParser( self.navigator.userAgent ).getBrowserName(); - - if (this.browser === 'Firefox') { - this.headers.forward.push('user-agent'); - this.headers.forward.push('content-type'); - } } /** * @@ -89,7 +78,7 @@ class UVServiceWorker extends EventEmitter { request, this, ultraviolet, - !this.method.empty.includes(request.method.toUpperCase()) + !emptyMethods.includes(request.method.toUpperCase()) ? await request.blob() : null ); @@ -172,7 +161,7 @@ class UVServiceWorker extends EventEmitter { this.emit('beforemod', resEvent); if (resEvent.intercepted) return resEvent.returnValue; - for (const name of this.headers.csp) { + for (const name of cspHeaders) { if (responseCtx.headers[name]) delete responseCtx.headers[name]; } @@ -312,7 +301,6 @@ class RequestContext { this.request = request; this.headers = Object.fromEntries([...request.headers.entries()]); this.method = request.method; - this.forward = [...worker.headers.forward]; this.address = worker.address; this.body = body || null; this.redirect = request.redirect;