diff --git a/src/entries/Background/db.ts b/src/entries/Background/db.ts index ea32ae6e..a85d0e55 100644 --- a/src/entries/Background/db.ts +++ b/src/entries/Background/db.ts @@ -325,18 +325,18 @@ export async function clearCookies(host: string) { }); } -export async function getCookies(host: string, name: string) { +export async function getCookies(link: string, name: string) { try { - const existing = await cookiesDb.sublevel(host).get(name); + const existing = await cookiesDb.sublevel(link).get(name); return existing; } catch (e) { return null; } } -export async function getCookiesByHost(host: string) { +export async function getCookiesByHost(link: string) { const ret: { [key: string]: string } = {}; - for await (const [key, value] of cookiesDb.sublevel(host).iterator()) { + for await (const [key, value] of cookiesDb.sublevel(link).iterator()) { ret[key] = value; } return ret; @@ -359,10 +359,10 @@ export async function getConnection(origin: string) { } } -export async function setHeaders(host: string, name: string, value?: string) { +export async function setHeaders(link: string, name: string, value?: string) { if (!value) return null; return mutex.runExclusive(async () => { - await headersDb.sublevel(host).put(name, value); + await headersDb.sublevel(link).put(name, value); return true; }); } @@ -382,9 +382,9 @@ export async function getHeaders(host: string, name: string) { return null; } } -export async function getHeadersByHost(host: string) { +export async function getHeadersByHost(link: string) { const ret: { [key: string]: string } = {}; - for await (const [key, value] of headersDb.sublevel(host).iterator()) { + for await (const [key, value] of headersDb.sublevel(link).iterator()) { ret[key] = value; } return ret; diff --git a/src/entries/Background/handlers.ts b/src/entries/Background/handlers.ts index b585ecef..75d07dd8 100644 --- a/src/entries/Background/handlers.ts +++ b/src/entries/Background/handlers.ts @@ -4,7 +4,7 @@ import mutex from './mutex'; import browser from 'webextension-polyfill'; import { addRequest } from '../../reducers/requests'; import { urlify } from '../../utils/misc'; -import { setCookies, setHeaders } from './db'; +import { getHeadersByHost, setCookies, setHeaders } from './db'; export const onSendHeaders = ( details: browser.WebRequest.OnSendHeadersDetailsType, ) => { @@ -14,9 +14,11 @@ export const onSendHeaders = ( if (method !== 'OPTIONS') { const cache = getCacheByTabId(tabId); const existing = cache.get(requestId); - const { hostname } = urlify(details.url) || {}; + const { origin, pathname } = urlify(details.url) || {}; - if (hostname && details.requestHeaders) { + const link = [origin, pathname].join(''); + + if (link && details.requestHeaders) { details.requestHeaders.forEach((header) => { const { name, value } = header; if (/^cookie$/i.test(name) && value) { @@ -24,10 +26,10 @@ export const onSendHeaders = ( .split(';') .map((v) => v.split('=')) .forEach((cookie) => { - setCookies(hostname, cookie[0].trim(), cookie[1]); + setCookies(link, cookie[0].trim(), cookie[1]); }); } else { - setHeaders(hostname, name, value); + setHeaders(link, name, value); } }); } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 43877863..9ebcc19f 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -303,20 +303,20 @@ export const makePlugin = async ( } if (config?.cookies) { - const cookies: { [hostname: string]: { [key: string]: string } } = {}; - for (const host of config.cookies) { - const cache = await getCookiesByHost(host); - cookies[host] = cache; + const cookies: { [link: string]: { [key: string]: string } } = {}; + for (const link of config.cookies) { + const cache = await getCookiesByHost(link); + cookies[link] = cache; } // @ts-ignore injectedConfig.cookies = JSON.stringify(cookies); } if (config?.headers) { - const headers: { [hostname: string]: { [key: string]: string } } = {}; - for (const host of config.headers) { - const cache = await getHeadersByHost(host); - headers[host] = cache; + const headers: { [link: string]: { [key: string]: string } } = {}; + for (const link of config.headers) { + const cache = await getHeadersByHost(link); + headers[link] = cache; } // @ts-ignore injectedConfig.headers = JSON.stringify(headers);