Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge] test-run #1262

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7b4d93d
feat(mv3): :sparkles: Patching countly-sdk-web
whizzzkid Jul 12, 2023
f3305fe
feat(mv3): :sparkles: Implementing Custom Async Store.
whizzzkid Jul 12, 2023
83af58f
chore(mv3): :adhesive_bandage: Hooking everything up together.
whizzzkid Jul 12, 2023
d504c71
fix(mv3): Countly Patching + ignite-metrics@2.0.0
whizzzkid Jul 13, 2023
4fab16a
fix(mv3): :adhesive_bandage: Patching the Patch
whizzzkid Jul 13, 2023
f02d6a2
fix: tests
whizzzkid Jul 13, 2023
dbab08c
fix: lint
whizzzkid Jul 13, 2023
394b13b
fix(mv3): :recycle: Refactoring `supportsBlock` Checks.
whizzzkid Jul 18, 2023
cbb4ac6
fix(mv3): Regex Bug
whizzzkid Jul 18, 2023
5794aea
feat: Migrating blocking redirection test to observing redirection test
whizzzkid Jul 18, 2023
0b0af76
fix(mv3): :wrench: Fixing the mocha-setup.
whizzzkid Jul 18, 2023
0de2e89
fix(mv3): :recycle: Moving Setup Files.
whizzzkid Jul 19, 2023
1d46a57
fix(mv3): gateway-redirect tests now fixed.
whizzzkid Jul 19, 2023
44653de
fix: :adhesive_bandage: Patching error messages
whizzzkid Jul 19, 2023
64fcde7
fix(patch): countly-web-sdk
whizzzkid Jul 19, 2023
66b13dc
fix(patch): :pin: Pinning countly-web-sdk to 23.2.2
whizzzkid Jul 19, 2023
39af513
Merge branch 'fix/analytics' into feat/redirection-tests
whizzzkid Jul 19, 2023
bf98b8f
fix(mv3): :lipstick: Fixing Lint
whizzzkid Jul 19, 2023
0b8b308
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 19, 2023
3b80b2a
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 19, 2023
50797d0
feat: protocol-handler-redirection-tests
whizzzkid Jul 19, 2023
46fca05
feat: more tests fixed
whizzzkid Jul 19, 2023
8e3aee2
fix: More tests
whizzzkid Jul 19, 2023
83ff056
fix: lint fix
whizzzkid Jul 19, 2023
38d7b60
test: merge mocha-setup files (#1246)
SgtPooki Jul 25, 2023
4039f0f
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 25, 2023
dd86afa
test: fix after merge
SgtPooki Jul 25, 2023
0e316a2
test: fix after merge
SgtPooki Jul 25, 2023
7b94054
fix: typerrors for localstorage
whizzzkid Jul 25, 2023
8d95a1f
fix: Updating test:functional_MV3 command.
whizzzkid Jul 26, 2023
9bbf271
fix: setup
whizzzkid Jul 26, 2023
5ce5de8
fix(test): Fixing tests
whizzzkid Jul 26, 2023
e5d42e0
fix(lint): Becuase Ofcourse
whizzzkid Jul 26, 2023
a260eb9
feat(test): scaffolding mv3 + mv2 calls in a single check.
whizzzkid Jul 27, 2023
eb8fea0
feat(test): unskipping and upgrading dnslink tests to mv3
whizzzkid Jul 27, 2023
cc109b0
feat(test): Upgrading workaround tests to MV3
whizzzkid Jul 27, 2023
441191e
fix(test): removing all skips with better checks.
whizzzkid Jul 27, 2023
5ac8417
fix(test): :recycle: Refactoring tests and removing redundant calls.
whizzzkid Jul 27, 2023
02042cb
fix(test): More Dryer
whizzzkid Jul 27, 2023
f3d4605
fix(test): one more
whizzzkid Jul 27, 2023
47d72f8
fix(test): :pencil2: Renaming isMv3TestingEnabled -> isManifestV3
whizzzkid Jul 27, 2023
239984d
fix(test): refactor expectNoRedirect
whizzzkid Jul 27, 2023
94cb141
fix(test): :recycle: Refactoring more.
whizzzkid Jul 27, 2023
e3e73c9
fix: replacing checks to undefined
whizzzkid Jul 27, 2023
80e7d51
fix: renaming expectNoRedirect -> ensureNoRedirect
whizzzkid Jul 27, 2023
7d1e97c
fix(test): Adding missing JSDoc
whizzzkid Jul 27, 2023
33b8062
fix(test): :shrug: how did this get removed.
whizzzkid Jul 28, 2023
ae23f4c
fix(test): :wastebasket: removed.
whizzzkid Jul 28, 2023
b77ab7b
fix(test): Suggestion
whizzzkid Jul 28, 2023
bb85dbb
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Jul 28, 2023
6fe39a3
fix(test): :adhesive_bandage: Bad Merge
whizzzkid Jul 28, 2023
e56bb6a
fix(test): sequential expectNoRedirect
lidel Aug 3, 2023
6bd8c3c
Update add-on/src/lib/redirect-handler/blockOrObserve.ts
whizzzkid Aug 4, 2023
7f68ab4
fix(mv3): :wrench: Modifying the default local redirect behaviour.
whizzzkid Aug 4, 2023
d94b9bb
Merge branch 'rc/3.0-mv3' into fix/default-rules
whizzzkid Aug 4, 2023
47ea944
Merge branch 'rc/3.0-mv3' into feat/redirection-tests
whizzzkid Aug 4, 2023
a817045
Merge branch 'rc/3.0-mv3' into fix/default-rules
whizzzkid Aug 4, 2023
045e660
fix(mv3): :wrench: Modifying the default local redirect behaviour.
whizzzkid Aug 4, 2023
f6561b9
Merge remote-tracking branch 'refs/remotes/origin/fix/default-rules' …
whizzzkid Aug 4, 2023
c020638
Merge branch 'feat/redirection-tests' into fix/default-rules
whizzzkid Aug 4, 2023
fc085b5
fix(mv3): :bug: Making rules less greedy
whizzzkid Aug 10, 2023
007f41f
fix(mv3): :sparkles: Dynamic Rules for subdomain gateways.
whizzzkid Aug 11, 2023
f18579b
fix(types): Adding ambient types for is-ipfs.
whizzzkid Aug 11, 2023
3e72d36
fix(test):
whizzzkid Aug 12, 2023
d36a282
fix(test): helper
whizzzkid Aug 12, 2023
6ee2d31
feat(mv3): less greedy rules
whizzzkid Aug 12, 2023
e592755
feat: Adding simpler regex for redirects from similar namespaces.
whizzzkid Aug 12, 2023
5c85d84
fix(lint): :rotating_light: Warnings
whizzzkid Aug 12, 2023
fca5fe2
feat(mv3): Better Default Rules (#1260)
whizzzkid Aug 15, 2023
832679d
Update add-on/src/lib/redirect-handler/blockOrObserve.ts
whizzzkid Aug 16, 2023
5e22cea
fix(docs): :pencil2: Adding comments
whizzzkid Aug 16, 2023
43478d6
refactor(regexFilters): :sparkles: Adding a base class for regexFilters.
whizzzkid Aug 16, 2023
fe40f59
refactor(regexFilters): :recycle: Moving subdomain filter to a subclass
whizzzkid Aug 16, 2023
7a631b6
refactor(regexFilters): :recycle: Moving namespace filter to a subclass
whizzzkid Aug 16, 2023
d5d47d7
refactor(regexFilters): :recycle: Moving common filter to a subclass
whizzzkid Aug 16, 2023
05c979f
feat(regexFilters): :sparkles: Hooking Up All together
whizzzkid Aug 16, 2023
7f78475
fix(lint): :pencil2: Lint
whizzzkid Aug 16, 2023
be5a7da
fix(regexFilters): :pencil2: Updating message.
whizzzkid Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
}
// poor-mans protocol handlers - https://github.com/ipfs/ipfs-companion/issues/164#issuecomment-328374052
if (state.catchUnhandledProtocols && mayContainUnhandledIpfsProtocol(request)) {
const fix = normalizedUnhandledIpfsProtocol(request, state.pubGwURLString)
const fix = await normalizedUnhandledIpfsProtocol(request, state.pubGwURLString)
if (fix) {
return fix
}
Expand Down Expand Up @@ -485,15 +485,15 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
* @param {object} input contains originUrl and redirectUrl.
* @returns
*/
function handleRedirection ({ originUrl, redirectUrl, request }) {
async function handleRedirection ({ originUrl, redirectUrl, request }) {
if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) {
resolvedRequestTracker.track(request)
if (supportsBlock) {
if (supportsBlock()) {
return { redirectUrl }
}

// Let browser handle redirection MV3 style.
addRuleToDynamicRuleSet({ originUrl, redirectUrl })
await addRuleToDynamicRuleSet({ originUrl, redirectUrl })
}
}

Expand Down
104 changes: 104 additions & 0 deletions add-on/src/lib/redirect-handler/baseRegexFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
export interface IRegexFilter {
originUrl: string
redirectUrl: string
}

export interface IFilter {
regexFilter: string
regexSubstitution: string
}

/**
* Base class for all regex filters.
*/
export class RegexFilter {
readonly _redirectUrl!: string
readonly _originUrl!: string
readonly originURL: URL
readonly redirectURL: URL
readonly originNS: string
readonly redirectNS: string
// by default we cannot handle the request.
_canHandle = false
regexFilter!: string
regexSubstitution!: string

constructor ({ originUrl, redirectUrl }: IRegexFilter) {
this._originUrl = originUrl
this._redirectUrl = redirectUrl
this.originURL = new URL(this._originUrl)
this.redirectURL = new URL(this._redirectUrl)
this.redirectNS = this.computeNamespaceFromUrl(this.redirectURL)
this.originNS = this.computeNamespaceFromUrl(this.originURL)
this.computeFilter()
this.normalizeRegexFilter()
}

/**
* Getter for the originUrl provided at construction.
*/
get originUrl (): string {
return this._originUrl
}

/**
* Getter for the redirectUrl provided at construction.
*/
get redirectUrl (): string {
return this._redirectUrl
}

/**
* Getter for the canHandle flag.
*/
get canHandle (): boolean {
return this._canHandle
}

/**
* Setter for the canHandle flag.
*/
set canHandle (value: boolean) {
this._canHandle = value
}

/**
* Getter for the filter. This is the regex filter and substitution.
*/
get filter (): IFilter {
if (!this.canHandle) {
throw new Error('Cannot handle this request')
}

return {
regexFilter: this.regexFilter,
regexSubstitution: this.regexSubstitution
}
}

/**
* Compute the regex filter and substitution.
* This is the main method that needs to be implemented by subclasses.
*/
computeFilter (): void {
throw new Error('Method not implemented.')
}

/**
* Normalize the regex filter. This is a helper method that can be used by subclasses.
*/
normalizeRegexFilter (): void {
this.regexFilter = this.regexFilter.replace(/https?\??/ig, 'https?')
}

/**
* Compute the namespace from the URL. This finds the first path segment.
* e.g. http://<gateway>/<namespace>/path/to/file/or/cid
*
* @param url URL
*/
computeNamespaceFromUrl ({ pathname }: URL): string {
// regex to match the first path segment.
return (/\/([^/]+)\//i.exec(pathname)?.[1] ?? '').toLowerCase()
}
}
98 changes: 53 additions & 45 deletions add-on/src/lib/redirect-handler/blockOrObserve.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import debug from 'debug'
import browser from 'webextension-polyfill'
import { CompanionState } from '../../types/companion.js'
import { SubdomainRedirectRegexFilter } from './subdomainRedirectRegexFilter.js'
import { NamespaceRedirectRegexFilter } from './namespaceRedirectRegexFilter.js'
import { IFilter, IRegexFilter, RegexFilter } from './baseRegexFilter.js'
import { CommonPatterRedirectRegexFilter } from './commonPatternRedirectRegexFilter.js'

// this won't work in webworker context. Needs to be enabled manually
// https://github.com/debug-js/debug/issues/916
const log = debug('ipfs-companion:redirect-handler:blockOrObserve')
log.error = debug('ipfs-companion:redirect-handler:blockOrObserve:error')

export const DEFAULT_NAMESPACES = new Set(['ipfs', 'ipns'])

export const GLOBAL_STATE_CHANGE = 'GLOBAL_STATE_CHANGE'
export const GLOBAL_STATE_OPTION_CHANGE = 'GLOBAL_STATE_OPTION_CHANGE'
export const DELETE_RULE_REQUEST = 'DELETE_RULE_REQUEST'
export const DELETE_RULE_REQUEST_SUCCESS = 'DELETE_RULE_REQUEST_SUCCESS'

// We need to match the rest of the URL, so we can use a wildcard.
export const RULE_REGEX_ENDING = '((?:[^\\.]|$).*)$'

interface regexFilterMap {
Expand All @@ -21,6 +29,7 @@ interface regexFilterMap {
interface redirectHandlerInput {
originUrl: string
redirectUrl: string
getPort: (state: CompanionState) => string
}

type messageToSelfType = typeof GLOBAL_STATE_CHANGE | typeof GLOBAL_STATE_OPTION_CHANGE | typeof DELETE_RULE_REQUEST
Expand All @@ -29,10 +38,16 @@ interface messageToSelf {
value?: string | Record<string, unknown>
}

export const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})`

// We need to check if the browser supports the declarativeNetRequest API.
// TODO: replace with check for `Blocking` in `chrome.webRequest.OnBeforeRequestOptions`
// which is currently a bug https://bugs.chromium.org/p/chromium/issues/detail?id=1427952
export const supportsBlock = !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES === 5000)
// this needs to be a function call, because in tests we mock browser.declarativeNetRequest
// the way sinon ends up stubbing it, it's not directly available in the global scope on import
// rather it gets replaced dynamically when the module is imported. Which means, we can't
// just check for the existence of the property, we need to call the browser instance at that point.
export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0)

/**
* Notify self about state change.
Expand Down Expand Up @@ -61,21 +76,28 @@ export async function notifyDeleteRule (id: number): Promise<void> {
*/
async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise<void> {
// this check ensures we don't send messages to ourselves if blocking mode is enabled.
if (!supportsBlock) {
const message: messageToSelf = { type: msg, value }
await browser.runtime.sendMessage({ message })
if (!supportsBlock()) {
const message: messageToSelf = { type: msg }
await browser.runtime.sendMessage(message)
}
}

const savedRegexFilters: Map<string, regexFilterMap> = new Map()
const DEFAULT_LOCAL_RULES: redirectHandlerInput[] = [
{
originUrl: 'http://127.0.0.1',
redirectUrl: 'http://localhost'
redirectUrl: 'http://localhost',
getPort: ({ gwURLString }): string => new URL(gwURLString).port
},
{
originUrl: 'http://[::1]',
redirectUrl: 'http://localhost'
redirectUrl: 'http://localhost',
getPort: ({ gwURLString }): string => new URL(gwURLString).port
},
{
originUrl: 'http://localhost',
redirectUrl: 'http://127.0.0.1',
getPort: ({ apiURL }): string => new URL(apiURL).port
}
]

Expand All @@ -97,10 +119,10 @@ export function isLocalHost (url: string): boolean {
* @param str URL string to escape
* @returns
*/
function escapeURLRegex (str: string): string {
export function escapeURLRegex (str: string): string {
// these characters are allowed in the URL, but not in the regex.
// eslint-disable-next-line no-useless-escape
const ALLOWED_CHARS_URL_REGEX = /([:\/\?#\[\]@!$&'\(\ )\*\+,;=-_\.~])/g
const ALLOWED_CHARS_URL_REGEX = /([:\/\?#\[\]@!$&'\(\ )\*\+,;=\-_\.~])/g
return str.replace(ALLOWED_CHARS_URL_REGEX, '\\$1')
}

Expand All @@ -111,43 +133,29 @@ function escapeURLRegex (str: string): string {
* @param redirectUrl
* @returns
*/
function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput): {
regexSubstitution: string
regexFilter: string
} {
// We can traverse the URL from the end, and find the first character that is different.
let commonIdx = 1
while (commonIdx < Math.min(originUrl.length, redirectUrl.length)) {
if (originUrl[originUrl.length - commonIdx] !== redirectUrl[redirectUrl.length - commonIdx]) {
break
function constructRegexFilter ({ originUrl, redirectUrl }: IRegexFilter): IFilter {
// the order is very important here, because we want to match the best possible filter.
const filtersToTryInOrder: Array<typeof RegexFilter> = [
SubdomainRedirectRegexFilter,
NamespaceRedirectRegexFilter,
CommonPatterRedirectRegexFilter
]

for (const Filter of filtersToTryInOrder) {
const filter = new Filter({ originUrl, redirectUrl })
if (filter.canHandle) {
return filter.filter
}
commonIdx += 1
}

// We can now construct the regex filter and substitution.
let regexSubstitution = redirectUrl.slice(0, redirectUrl.length - commonIdx + 1) + '\\1'
// We need to escape the characters that are allowed in the URL, but not in the regex.
const regexFilterFirst = escapeURLRegex(originUrl.slice(0, originUrl.length - commonIdx + 1))
// We need to match the rest of the URL, so we can use a wildcard.
const RULE_REGEX_ENDING = '((?:[^\\.]|$).*)$'
let regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`.replace(/https?/ig, 'https?')

// This method does not parse:
// originUrl: "https://awesome.ipfs.io/"
// redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/"
// that ends up with capturing all urls which we do not want.
if (regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) {
const subdomain = new URL(originUrl).hostname
regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}`
regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`)
}

return { regexSubstitution, regexFilter }
// this is just to satisfy the compiler, this should never happen. Because CommonPatterRedirectRegexFilter can always
// handle.
return new CommonPatterRedirectRegexFilter({ originUrl, redirectUrl }).filter
}

// If the browser supports the declarativeNetRequest API, we can block the request.
export function getExtraInfoSpec<T> (additionalParams: T[] = []): T[] {
if (supportsBlock) {
if (supportsBlock()) {
return ['blocking' as T, ...additionalParams]
}
return additionalParams
Expand Down Expand Up @@ -239,15 +247,15 @@ async function reconcileRulesAndRemoveOld (state: CompanionState): Promise<void>
if (rules.length === 0) {
// we need to populate old rules.
for (const [regexFilter, { regexSubstitution, id }] of savedRegexFilters.entries()) {
addRules.push(generateRule(id, regexFilter, regexSubstitution))
addRules.push(generateAddRule(id, regexFilter, regexSubstitution))
}
}

// make sure that the default rules are added.
for (const { originUrl, redirectUrl } of DEFAULT_LOCAL_RULES) {
const { port } = new URL(state.gwURLString)
const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}(.*)$`
const regexSubstitution = `${redirectUrl}:${port}\\1`
for (const { originUrl, redirectUrl, getPort } of DEFAULT_LOCAL_RULES) {
const port = getPort(state)
const regexFilter = `^${escapeURLRegex(`${originUrl}:${port}`)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}`
const regexSubstitution = `${redirectUrl}:${port}/\\1/\\2`

if (!savedRegexFilters.has(regexFilter)) {
// We need to add the new rule.
Expand Down Expand Up @@ -276,7 +284,7 @@ function saveAndGenerateRule (
const id = Math.floor(Math.random() * 29999)
// We need to save the regex filter and ID to check if the rule already exists later.
savedRegexFilters.set(regexFilter, { id, regexSubstitution })
return generateRule(id, regexFilter, regexSubstitution, excludedInitiatorDomains)
return generateAddRule(id, regexFilter, regexSubstitution, excludedInitiatorDomains)
}

/**
Expand All @@ -287,7 +295,7 @@ function saveAndGenerateRule (
* @param excludedInitiatorDomains - The domains that are excluded from the rule.
* @returns
*/
function generateRule (
export function generateAddRule (
id: number,
regexFilter: string,
regexSubstitution: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { IRegexFilter, RegexFilter } from './baseRegexFilter.js'
import { RULE_REGEX_ENDING, escapeURLRegex } from './blockOrObserve.js'

export class CommonPatterRedirectRegexFilter extends RegexFilter {
constructor ({ originUrl, redirectUrl }: IRegexFilter) {
super({ originUrl, redirectUrl })

// this filter is the worst case scenario, we can handle any redirect.
this._canHandle = true
}

computeFilter (): void {
// We can traverse the URL from the end, and find the first character that is different.
let commonIdx = 1
while (commonIdx < Math.min(this.originUrl.length, this.redirectUrl.length)) {
if (this.originUrl[this.originUrl.length - commonIdx] !== this.redirectUrl[this.redirectUrl.length - commonIdx]) {
break
}
commonIdx += 1
}

// We can now construct the regex filter and substitution.
this.regexSubstitution = this.redirectUrl.slice(0, this.redirectUrl.length - commonIdx + 1) + '\\1'
// We need to escape the characters that are allowed in the URL, but not in the regex.
const regexFilterFirst = escapeURLRegex(this.originUrl.slice(0, this.originUrl.length - commonIdx + 1))
this.regexFilter = `^${regexFilterFirst}${RULE_REGEX_ENDING}`
// calling normalize should add the protocol in the regexFilter.
this.normalizeRegexFilter()

// This method does not parse:
// originUrl: "https://awesome.ipfs.io/"
// redirectUrl: "http://localhost:8081/ipns/awesome.ipfs.io/"
// that ends up with capturing all urls which we do not want.
if (this.regexFilter === `^https?\\:\\/${RULE_REGEX_ENDING}`) {
const subdomain = new URL(this.originUrl).hostname
this.regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${RULE_REGEX_ENDING}`
this.regexSubstitution = this.regexSubstitution.replace('\\1', `/${subdomain}\\1`)
}
}
}
24 changes: 24 additions & 0 deletions add-on/src/lib/redirect-handler/namespaceRedirectRegexFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DEFAULT_NAMESPACES, RULE_REGEX_ENDING, defaultNSRegexStr, escapeURLRegex } from './blockOrObserve.js'
import { IRegexFilter, RegexFilter } from './baseRegexFilter.js'

export class NamespaceRedirectRegexFilter extends RegexFilter {
constructor ({ originUrl, redirectUrl }: IRegexFilter) {
super({ originUrl, redirectUrl })
this._canHandle = DEFAULT_NAMESPACES.has(this.originNS) &&
DEFAULT_NAMESPACES.has(this.redirectNS) &&
this.originNS === this.redirectNS &&
this.originURL.searchParams.get('uri') == null
}

computeFilter (): void {
// if the namespaces are the same, we can generate simpler regex.
// The only value that needs special handling is the `uri` param.
// A redirect like
// https://ipfs.io/ipfs/QmZMxU -> http://localhost:8080/ipfs/QmZMxU
const [originFirst, originLast] = this.originUrl.split(`/${this.originNS}/`)
this.regexFilter = `^${escapeURLRegex(originFirst)}\\/${defaultNSRegexStr}\\/${RULE_REGEX_ENDING}`
this.regexSubstitution = this.redirectUrl
.replace(`/${this.redirectNS}/`, '/\\1/')
.replace(originLast, '\\2')
}
}
Loading