summaryrefslogtreecommitdiffstats
path: root/examples/proxy-agent.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/proxy-agent.js')
-rw-r--r--examples/proxy-agent.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/proxy-agent.js b/examples/proxy-agent.js
new file mode 100644
index 0000000..7caf836
--- /dev/null
+++ b/examples/proxy-agent.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const { request, setGlobalDispatcher, ProxyAgent } = require('../')
+
+setGlobalDispatcher(new ProxyAgent('http://localhost:8000/'))
+
+async function main () {
+ const {
+ statusCode,
+ headers,
+ trailers,
+ body
+ // send the request via the http://localhost:8000/ HTTP proxy
+ } = await request('http://localhost:3000/undici')
+
+ console.log('response received', statusCode)
+ console.log('headers', headers)
+
+ for await (const data of body) {
+ console.log('data', data)
+ }
+
+ console.log('trailers', trailers)
+}
+main()