*Force redirect from https to http
This commit is contained in:
parent
67d94d1c47
commit
fc0ca7d847
|
@ -121,11 +121,18 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
async handleRequest(
|
async handleRequest(
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
let urlPath = new URL(details.url).pathname;
|
let urlObj = new URL(details.url);
|
||||||
|
let urlPath = urlObj.pathname;
|
||||||
let hash = this.getData(details, "hash");
|
let hash = this.getData(details, "hash");
|
||||||
let resp: StatFileResponse | null = null;
|
let resp: StatFileResponse | null = null;
|
||||||
let fetchMethod: typeof fetchIpfs | typeof fetchIpns;
|
let fetchMethod: typeof fetchIpfs | typeof fetchIpns;
|
||||||
let err;
|
let err;
|
||||||
|
|
||||||
|
if (urlObj.protocol == "https") {
|
||||||
|
urlObj.protocol = "http";
|
||||||
|
return { redirectUrl: urlObj.toString() };
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ipfsPath(hash)) {
|
if (ipfsPath(hash)) {
|
||||||
hash = hash.replace("/ipfs/", "");
|
hash = hash.replace("/ipfs/", "");
|
||||||
|
@ -264,6 +271,23 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
);
|
);
|
||||||
data = new TextEncoder().encode(data);
|
data = new TextEncoder().encode(data);
|
||||||
}
|
}
|
||||||
|
/* if (contentType === "text/html") {
|
||||||
|
data = new TextDecoder("utf-8", { fatal: true }).decode(data);
|
||||||
|
let htmlDoc = new DOMParser().parseFromString(
|
||||||
|
data as string,
|
||||||
|
contentType
|
||||||
|
);
|
||||||
|
let found = htmlDoc.documentElement.querySelectorAll(
|
||||||
|
'meta[http-equiv="Content-Security-Policy"]'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (found.length) {
|
||||||
|
found.forEach((item) => item.remove());
|
||||||
|
data = htmlDoc.documentElement.outerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new TextEncoder().encode(data);
|
||||||
|
}*/
|
||||||
filter.write(data);
|
filter.write(data);
|
||||||
} else if (mode == CONTENT_MODE_CHUNKED) {
|
} else if (mode == CONTENT_MODE_CHUNKED) {
|
||||||
buffer.forEach((data) => filter.write(data));
|
buffer.forEach((data) => filter.write(data));
|
||||||
|
|
|
@ -31,8 +31,15 @@ export default class SkynetProvider extends BaseProvider {
|
||||||
details: OnBeforeRequestDetailsType
|
details: OnBeforeRequestDetailsType
|
||||||
): Promise<BlockingResponse | boolean> {
|
): Promise<BlockingResponse | boolean> {
|
||||||
const dns = await this.resolveDns(details);
|
const dns = await this.resolveDns(details);
|
||||||
let path = new URL(details.url).pathname;
|
let urlObj = new URL(details.url);
|
||||||
|
let path = urlObj.pathname;
|
||||||
let fileData: any, err;
|
let fileData: any, err;
|
||||||
|
|
||||||
|
if (urlObj.protocol == "https") {
|
||||||
|
urlObj.protocol = "http";
|
||||||
|
return { redirectUrl: urlObj.toString() };
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
[fileData, err] = await downloadSkylink(dns, path);
|
[fileData, err] = await downloadSkylink(dns, path);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
Reference in New Issue