-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connecting through a proxy #568
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to show how to use it with Pool
?
It would really be nice to also include some ways of having a ProxyAgent
.
It works in the exact same way with both |
Here is an example for the Agent API: import { request, setGlobalAgent, ProxyAgent } from 'undici'
setGlobalAgent(new ProxyAgent('https://my.proxy.agent/'))
const {
statusCode,
headers,
trailers,
body
// send the request via the 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) |
Codecov Report
@@ Coverage Diff @@
## master #568 +/- ##
==========================================
- Coverage 99.57% 99.57% -0.01%
==========================================
Files 16 16
Lines 1400 1399 -1
==========================================
- Hits 1394 1393 -1
Misses 6 6
Continue to review full report at Codecov.
|
FYI, you don't need to add the ProxyAgent right now. It can be another issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
is there an example with proxying a POST request? |
No but it would be a good PR. |
This pr adds a test and the documentation to show how to connect through a proxy :)
I had to remove the super complex regex as it was not validating all absolute urls (eg:
http://localhost:8080
didn't pass the check). I think that lazily checking the protocol is enough, as trying to save all users from themselves is impossible./cc @szmarczak
Closes #427