mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-21 04:48:00 -05:00
fix(http): options not parsed accurately (#2914)
* fix(http): options not parsed accurately * fix lint * remove boilerplate code'
This commit is contained in:
committed by
GitHub
parent
294b168ed9
commit
145db9d8c3
@@ -1,6 +1,7 @@
|
||||
import dns from 'dns/promises'
|
||||
import http from 'http'
|
||||
import https from 'https'
|
||||
import type { LookupFunction } from 'net'
|
||||
import { createLogger } from '@sim/logger'
|
||||
import * as ipaddr from 'ipaddr.js'
|
||||
|
||||
@@ -907,26 +908,28 @@ export async function secureFetchWithPinnedIP(
|
||||
const isIPv6 = resolvedIP.includes(':')
|
||||
const family = isIPv6 ? 6 : 4
|
||||
|
||||
const agentOptions = {
|
||||
lookup: (
|
||||
_hostname: string,
|
||||
_options: unknown,
|
||||
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void
|
||||
) => {
|
||||
const lookup: LookupFunction = (_hostname, options, callback) => {
|
||||
if (options.all) {
|
||||
callback(null, [{ address: resolvedIP, family }])
|
||||
} else {
|
||||
callback(null, resolvedIP, family)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const agent = isHttps
|
||||
? new https.Agent(agentOptions as https.AgentOptions)
|
||||
: new http.Agent(agentOptions as http.AgentOptions)
|
||||
const agentOptions: http.AgentOptions = { lookup }
|
||||
|
||||
const agent = isHttps ? new https.Agent(agentOptions) : new http.Agent(agentOptions)
|
||||
|
||||
// Remove accept-encoding since Node.js http/https doesn't auto-decompress
|
||||
// Headers are lowercase due to Web Headers API normalization in executeToolRequest
|
||||
const { 'accept-encoding': _, ...sanitizedHeaders } = options.headers ?? {}
|
||||
|
||||
const requestOptions: http.RequestOptions = {
|
||||
hostname: parsed.hostname,
|
||||
port,
|
||||
path: parsed.pathname + parsed.search,
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers || {},
|
||||
headers: sanitizedHeaders,
|
||||
agent,
|
||||
timeout: options.timeout || 30000,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user