Skip to content

Creates a ProxyAgent to forward all HTTP request to an HTTP proxy #569

@mcollina

Description

@mcollina

Here is some example call

import { request, setGlobalAgent, ProxyAgent } from 'undici'

setGlobalDispatcher(new ProxyAgent('https://my.proxy.agent/'))

const {
  statusCode,
  headers,
  trailers,
  body
  // send the request via the https://my.proxy.agent/ HTTP proxy
} = await request('http://localhost:3000/foo')

console.log('response received', statusCode)
console.log('headers', headers)

for await (const data of body) {
  console.log('data', data)
}

console.log('trailers', trailers)

Follow up from #568

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions