Skip to content

Commit

Permalink
Respect proxies when fetching link previews
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Oct 14, 2021
1 parent 1f4d01f commit 92f7259
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ts/linkPreviews/linkPreviewFetch.ts
Expand Up @@ -54,7 +54,7 @@ const MAX_DATE = new Date(3000, 0, 1).valueOf();

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 = {
title: string;
Expand Down
16 changes: 14 additions & 2 deletions ts/textsecure/WebAPI.ts
Expand Up @@ -999,6 +999,14 @@ export function initialize({
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!
return {
getSocketStatus,
Expand Down Expand Up @@ -1968,7 +1976,7 @@ export function initialize({
abortSignal: AbortSignal
) {
return linkPreviewFetch.fetchLinkPreviewMetadata(
fetch,
fetchForLinkPreviews,
href,
abortSignal
);
Expand All @@ -1978,7 +1986,11 @@ export function initialize({
href: string,
abortSignal: AbortSignal
) {
return linkPreviewFetch.fetchLinkPreviewImage(fetch, href, abortSignal);
return linkPreviewFetch.fetchLinkPreviewImage(
fetchForLinkPreviews,
href,
abortSignal
);
}

async function makeProxiedRequest(
Expand Down

0 comments on commit 92f7259

Please sign in to comment.