Respect proxies when fetching link previews
This commit is contained in:
parent
1f4d01f21a
commit
92f7259272
2 changed files with 15 additions and 3 deletions
|
@ -54,7 +54,7 @@ const MAX_DATE = new Date(3000, 0, 1).valueOf();
|
||||||
|
|
||||||
const emptyContentType = { type: null, charset: null };
|
const emptyContentType = { type: null, charset: null };
|
||||||
|
|
||||||
type FetchFn = (href: string, init: RequestInit) => Promise<Response>;
|
export type FetchFn = (href: string, init: RequestInit) => Promise<Response>;
|
||||||
|
|
||||||
export type LinkPreviewMetadata = {
|
export type LinkPreviewMetadata = {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
|
@ -999,6 +999,14 @@ export function initialize({
|
||||||
socketManager.authenticate({ username, password });
|
socketManager.authenticate({ username, password });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fetchForLinkPreviews: linkPreviewFetch.FetchFn;
|
||||||
|
if (proxyUrl) {
|
||||||
|
const agent = new ProxyAgent(proxyUrl);
|
||||||
|
fetchForLinkPreviews = (href, init) => fetch(href, { ...init, agent });
|
||||||
|
} else {
|
||||||
|
fetchForLinkPreviews = fetch;
|
||||||
|
}
|
||||||
|
|
||||||
// Thanks, function hoisting!
|
// Thanks, function hoisting!
|
||||||
return {
|
return {
|
||||||
getSocketStatus,
|
getSocketStatus,
|
||||||
|
@ -1968,7 +1976,7 @@ export function initialize({
|
||||||
abortSignal: AbortSignal
|
abortSignal: AbortSignal
|
||||||
) {
|
) {
|
||||||
return linkPreviewFetch.fetchLinkPreviewMetadata(
|
return linkPreviewFetch.fetchLinkPreviewMetadata(
|
||||||
fetch,
|
fetchForLinkPreviews,
|
||||||
href,
|
href,
|
||||||
abortSignal
|
abortSignal
|
||||||
);
|
);
|
||||||
|
@ -1978,7 +1986,11 @@ export function initialize({
|
||||||
href: string,
|
href: string,
|
||||||
abortSignal: AbortSignal
|
abortSignal: AbortSignal
|
||||||
) {
|
) {
|
||||||
return linkPreviewFetch.fetchLinkPreviewImage(fetch, href, abortSignal);
|
return linkPreviewFetch.fetchLinkPreviewImage(
|
||||||
|
fetchForLinkPreviews,
|
||||||
|
href,
|
||||||
|
abortSignal
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function makeProxiedRequest(
|
async function makeProxiedRequest(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue