*Add serverProvider which supports ip's and hostnames, and does not filter content

This commit is contained in:
Derrick Hammer 2022-07-31 01:36:06 -04:00
parent 8fa77fe104
commit 03c9f543d9
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,31 @@
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);
return { type: "http", host: dns, port: 80 };
}
}

View File

@ -3,6 +3,7 @@ import tldEnum from "@lumeweb/tld-enum";
import WebEngine from "../webEngine.js"; import WebEngine from "../webEngine.js";
import InternalProvider from "../contentProviders/internalProvider.js"; import InternalProvider from "../contentProviders/internalProvider.js";
import SkynetProvider from "../contentProviders/skynetProvider.js"; import SkynetProvider from "../contentProviders/skynetProvider.js";
import ServerProvider from "../contentProviders/serverProvider.js";
import { init } from "libkernel"; import { init } from "libkernel";
declare var browser: any; // tsc declare var browser: any; // tsc
@ -188,6 +189,7 @@ browser.runtime.onConnect.addListener(bridgeListener);
const engine = new WebEngine(); const engine = new WebEngine();
engine.registerContentProvider(new InternalProvider(engine)); engine.registerContentProvider(new InternalProvider(engine));
engine.registerContentProvider(new ServerProvider(engine));
engine.registerContentProvider(new SkynetProvider(engine)); engine.registerContentProvider(new SkynetProvider(engine));
// @ts-ignore // @ts-ignore