This repository has been archived on 2023-12-17. You can view files and clone it, but cannot push or open issues or pull requests.
2022-07-31 05:36:06 +00:00
|
|
|
import BaseProvider from "./baseProvider.js";
|
|
|
|
import {
|
|
|
|
BlockingResponse,
|
|
|
|
HttpHeaders,
|
|
|
|
OnBeforeRequestDetailsType,
|
|
|
|
OnHeadersReceivedDetailsType,
|
|
|
|
OnRequestDetailsType,
|
|
|
|
} from "../types.js";
|
|
|
|
import { validSkylink } from "libskynet";
|
|
|
|
import { downloadSkylink, isDomain, isIp, requestProxies } from "../util.js";
|
|
|
|
import browser from "@lumeweb/webextension-polyfill";
|
|
|
|
|
|
|
|
export default class ServerProvider extends BaseProvider {
|
|
|
|
async shouldHandleRequest(
|
|
|
|
details: OnBeforeRequestDetailsType
|
|
|
|
): Promise<boolean> {
|
|
|
|
const dns = await this.resolveDns(details);
|
|
|
|
|
|
|
|
if (dns && (isDomain(dns) || isIp(dns))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async handleProxy(details: OnRequestDetailsType): Promise<any> {
|
|
|
|
const dns = await this.resolveDns(details);
|
|
|
|
|
2022-08-01 04:28:07 +00:00
|
|
|
if (isIp(dns) || isDomain(dns)) {
|
|
|
|
return { type: "http", host: dns, port: 80 };
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-07-31 05:36:06 +00:00
|
|
|
}
|
|
|
|
}
|