mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 12:00:02 -04:00
Minor Change (oops)
This commit is contained in:
parent
af2ca7e034
commit
6bd7e10c4d
31 changed files with 34771 additions and 1 deletions
34
src/Corrosion/lib/cookie.js
Normal file
34
src/Corrosion/lib/cookie.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const { SetCookie, CookieStore } = require('./cookie-parser');
|
||||
|
||||
class CookieRewriter {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
};
|
||||
decode(store, config = {}) {
|
||||
const url = new URL(config.url);
|
||||
const cookies = new CookieStore(store);
|
||||
cookies.forEach((val, key) => {
|
||||
if (!key.includes('@') || key.slice(key.length - url.hostname.length) != url.hostname) return cookies.delete(key);
|
||||
cookies.delete(key);
|
||||
cookies.set(key.substr(0, key.length - url.hostname.length - 1), val);
|
||||
});
|
||||
return cookies.serialize();
|
||||
};
|
||||
encode(input, config = {}) {
|
||||
if (Array.isArray(input)) {
|
||||
const rw = [ ...input ];
|
||||
for (let i in rw) rw[i] = this.encode(rw[i], config);
|
||||
return rw;
|
||||
};
|
||||
const url = new URL(config.url);
|
||||
const cookie = new SetCookie(input);
|
||||
if (!cookie.name) return null;
|
||||
cookie.domain = config.domain;
|
||||
cookie.secure = config.secure;
|
||||
cookie.name += `@${url.hostname}`;
|
||||
cookie.path = this.ctx.prefix;
|
||||
return cookie.serialize() || '';
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = CookieRewriter;
|
Loading…
Add table
Add a link
Reference in a new issue