@@ -21,12 +21,7 @@ import {
2121 createServiceAuthHeaders ,
2222 createServiceJwt ,
2323} from '@atproto/xrpc-server'
24- import {
25- Fetch ,
26- isUnicastIp ,
27- safeFetchWrap ,
28- unicastLookup ,
29- } from '@atproto-labs/fetch-node'
24+ import { Fetch , safeFetchWrap } from '@atproto-labs/fetch-node'
3025import { AccountManager } from './account-manager/account-manager.js'
3126import { OAuthStore } from './account-manager/oauth-store.js'
3227import { ScopeReferenceGetter } from './account-manager/scope-reference-getter.js'
@@ -47,6 +42,7 @@ import { ImageUrlBuilder } from './image/image-url-builder.js'
4742import { fetchLogger , lexiconResolverLogger , oauthLogger } from './logger.js'
4843import { ServerMailer } from './mailer/index.js'
4944import { ModerationMailer } from './mailer/moderation.js'
45+ import { buildProxyAgent } from './pipethrough.js'
5046import { LocalViewer , LocalViewerCreator } from './read-after-write/viewer.js'
5147import { getRedisClient } from './redis.js'
5248import { Sequencer } from './sequencer/index.js'
@@ -295,36 +291,7 @@ export class AppContext {
295291 )
296292
297293 // An agent for performing HTTP requests based on user provided URLs.
298- const proxyAgentBase = new undici . Agent ( {
299- allowH2 : cfg . proxy . allowHTTP2 , // This is experimental
300- headersTimeout : cfg . proxy . headersTimeout ,
301- maxResponseSize : cfg . proxy . maxResponseSize ,
302- bodyTimeout : cfg . proxy . bodyTimeout ,
303- factory : cfg . proxy . disableSsrfProtection
304- ? undefined
305- : ( origin , opts ) => {
306- const { protocol, hostname } =
307- origin instanceof URL ? origin : new URL ( origin )
308- if ( protocol !== 'https:' ) {
309- throw new Error ( `Forbidden protocol "${ protocol } "` )
310- }
311- if ( isUnicastIp ( hostname ) === false ) {
312- throw new Error ( 'Hostname resolved to non-unicast address' )
313- }
314- return new undici . Pool ( origin , opts )
315- } ,
316- connect : {
317- lookup : cfg . proxy . disableSsrfProtection ? undefined : unicastLookup ,
318- } ,
319- } )
320- const proxyAgent =
321- cfg . proxy . maxRetries > 0
322- ? new undici . RetryAgent ( proxyAgentBase , {
323- statusCodes : [ ] , // Only retry on socket errors
324- methods : [ 'GET' , 'HEAD' ] ,
325- maxRetries : cfg . proxy . maxRetries ,
326- } )
327- : proxyAgentBase
294+ const proxyAgent = buildProxyAgent ( cfg . proxy )
328295
329296 /**
330297 * A fetch() function that protects against SSRF attacks, large responses &
0 commit comments