*Add serverProvider which supports ip's and hostnames, and does not filter content
This commit is contained in:
parent
8fa77fe104
commit
03c9f543d9
|
@ -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 };
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
Reference in New Issue