|
| 1 | +import type { LookupAddress, LookupOptions } from 'dns' |
1 | 2 | import dns from 'dns/promises' |
2 | 3 | import http from 'http' |
3 | 4 | import https from 'https' |
@@ -907,26 +908,37 @@ export async function secureFetchWithPinnedIP( |
907 | 908 | const isIPv6 = resolvedIP.includes(':') |
908 | 909 | const family = isIPv6 ? 6 : 4 |
909 | 910 |
|
910 | | - const agentOptions = { |
| 911 | + const agentOptions: http.AgentOptions = { |
911 | 912 | lookup: ( |
912 | 913 | _hostname: string, |
913 | | - _options: unknown, |
914 | | - callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void |
| 914 | + options: LookupOptions, |
| 915 | + callback: ( |
| 916 | + err: NodeJS.ErrnoException | null, |
| 917 | + address: string | LookupAddress[], |
| 918 | + family?: number |
| 919 | + ) => void |
915 | 920 | ) => { |
916 | | - callback(null, resolvedIP, family) |
| 921 | + if (options.all) { |
| 922 | + callback(null, [{ address: resolvedIP, family }]) |
| 923 | + } else { |
| 924 | + callback(null, resolvedIP, family) |
| 925 | + } |
917 | 926 | }, |
918 | 927 | } |
919 | 928 |
|
920 | | - const agent = isHttps |
921 | | - ? new https.Agent(agentOptions as https.AgentOptions) |
922 | | - : new http.Agent(agentOptions as http.AgentOptions) |
| 929 | + const agent = isHttps ? new https.Agent(agentOptions) : new http.Agent(agentOptions) |
| 930 | + |
| 931 | + // Remove accept-encoding since Node.js http/https doesn't auto-decompress |
| 932 | + // Headers are lowercase due to Web Headers API normalization in executeToolRequest |
| 933 | + const sanitizedHeaders = { ...options.headers } |
| 934 | + sanitizedHeaders['accept-encoding'] = undefined |
923 | 935 |
|
924 | 936 | const requestOptions: http.RequestOptions = { |
925 | 937 | hostname: parsed.hostname, |
926 | 938 | port, |
927 | 939 | path: parsed.pathname + parsed.search, |
928 | 940 | method: options.method || 'GET', |
929 | | - headers: options.headers || {}, |
| 941 | + headers: sanitizedHeaders, |
930 | 942 | agent, |
931 | 943 | timeout: options.timeout || 30000, |
932 | 944 | } |
|
0 commit comments