mirror of
https://github.com/linkwarden/linkwarden.git
synced 2026-03-03 03:47:02 +00:00
fix INVALID_PROTOCOL when saving http website
Using a https agent to fetch a http site causes this error: TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import fetch from "node-fetch";
|
||||
import https from "https";
|
||||
import http from "http";
|
||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||
import { SocksProxyAgent } from "socks-proxy-agent";
|
||||
|
||||
@@ -8,10 +9,12 @@ export default async function fetchTitleAndHeaders(url: string) {
|
||||
return { title: "", headers: null };
|
||||
|
||||
try {
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized:
|
||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||
});
|
||||
const httpsAgent = url?.startsWith("http://")
|
||||
? new http.Agent({})
|
||||
: new https.Agent({
|
||||
rejectUnauthorized:
|
||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||
});
|
||||
|
||||
// fetchOpts allows a proxy to be defined
|
||||
let fetchOpts = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fetch from "node-fetch";
|
||||
import https from "https";
|
||||
import http from "http";
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import { SocksProxyAgent } from "socks-proxy-agent";
|
||||
|
||||
@@ -7,10 +8,12 @@ export default async function fetchHeaders(url: string) {
|
||||
if (process.env.IGNORE_URL_SIZE_LIMIT === "true") return null;
|
||||
|
||||
try {
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized:
|
||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||
});
|
||||
const httpsAgent = url.startsWith("http://")
|
||||
? new http.Agent({})
|
||||
: new https.Agent({
|
||||
rejectUnauthorized:
|
||||
process.env.IGNORE_UNAUTHORIZED_CA === "true" ? false : true,
|
||||
});
|
||||
|
||||
let fetchOpts = {
|
||||
method: "HEAD",
|
||||
|
||||
Reference in New Issue
Block a user