separate consts

This commit is contained in:
David Reed 2022-11-18 20:28:50 -05:00
parent 015045f2c5
commit 5e71b8138b
No known key found for this signature in database
GPG key ID: 2211691D8A1EE72F

View file

@ -10,17 +10,7 @@
*/ */
const Ultraviolet = globalThis.Ultraviolet; const Ultraviolet = globalThis.Ultraviolet;
class UVServiceWorker extends EventEmitter { const cspHeaders = [
constructor(config = __uv$config) {
super();
if (!config.bare) config.bare = '/bare/';
if (!config.prefix) config.prefix = '/service/';
this.addresses =
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-embedder-policy',
'cross-origin-opener-policy', 'cross-origin-opener-policy',
'cross-origin-resource-policy', 'cross-origin-resource-policy',
@ -37,15 +27,19 @@ class UVServiceWorker extends EventEmitter {
'x-permitted-cross-domain-policies', 'x-permitted-cross-domain-policies',
'x-powered-by', 'x-powered-by',
'x-xss-protection', 'x-xss-protection',
], ];
forward: ['accept-encoding', 'connection', 'content-length'], const emptyMethods = ['GET', 'HEAD'];
}; const emptyStatus = [204, 304];
this.method = {
empty: ['GET', 'HEAD'], class UVServiceWorker extends EventEmitter {
}; constructor(config = __uv$config) {
this.statusCode = { super();
empty: [204, 304], if (!config.bare) config.bare = '/bare/';
}; if (!config.prefix) config.prefix = '/service/';
this.addresses =
typeof config.bare === 'string'
? [new URL(config.bare, location)]
: config.bare.map((str) => new URL(str, location));
this.config = config; this.config = config;
/** /**
* @type {InstanceType<Ultraviolet['BareClient']>} * @type {InstanceType<Ultraviolet['BareClient']>}
@ -56,11 +50,6 @@ class UVServiceWorker extends EventEmitter {
this.browser = Ultraviolet.Bowser.getParser( this.browser = Ultraviolet.Bowser.getParser(
self.navigator.userAgent self.navigator.userAgent
).getBrowserName(); ).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, request,
this, this,
ultraviolet, ultraviolet,
!this.method.empty.includes(request.method.toUpperCase()) !emptyMethods.includes(request.method.toUpperCase())
? await request.blob() ? await request.blob()
: null : null
); );
@ -172,7 +161,7 @@ class UVServiceWorker extends EventEmitter {
this.emit('beforemod', resEvent); this.emit('beforemod', resEvent);
if (resEvent.intercepted) return resEvent.returnValue; 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]; if (responseCtx.headers[name]) delete responseCtx.headers[name];
} }
@ -312,7 +301,6 @@ class RequestContext {
this.request = request; this.request = request;
this.headers = Object.fromEntries([...request.headers.entries()]); this.headers = Object.fromEntries([...request.headers.entries()]);
this.method = request.method; this.method = request.method;
this.forward = [...worker.headers.forward];
this.address = worker.address; this.address = worker.address;
this.body = body || null; this.body = body || null;
this.redirect = request.redirect; this.redirect = request.redirect;