separate consts
This commit is contained in:
parent
015045f2c5
commit
5e71b8138b
1 changed files with 23 additions and 35 deletions
44
src/uv.sw.js
44
src/uv.sw.js
|
|
@ -10,17 +10,7 @@
|
|||
*/
|
||||
const Ultraviolet = globalThis.Ultraviolet;
|
||||
|
||||
class UVServiceWorker extends EventEmitter {
|
||||
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: [
|
||||
const cspHeaders = [
|
||||
'cross-origin-embedder-policy',
|
||||
'cross-origin-opener-policy',
|
||||
'cross-origin-resource-policy',
|
||||
|
|
@ -37,15 +27,19 @@ class UVServiceWorker extends EventEmitter {
|
|||
'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],
|
||||
};
|
||||
];
|
||||
const emptyMethods = ['GET', 'HEAD'];
|
||||
const emptyStatus = [204, 304];
|
||||
|
||||
class UVServiceWorker extends EventEmitter {
|
||||
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.config = config;
|
||||
/**
|
||||
* @type {InstanceType<Ultraviolet['BareClient']>}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue