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.
extension/src/contentProviders/serverProvider.ts

28 lines
706 B
TypeScript
Raw Normal View History

import BaseProvider from "./baseProvider.js";
2022-08-14 12:21:21 +00:00
import { OnBeforeRequestDetailsType, OnRequestDetailsType } from "../types.js";
import { isDomain, isIp } from "../util.js";
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);
if (isIp(dns) || isDomain(dns)) {
return { type: "http", host: dns, port: 80 };
}
return false;
}
}