Conversation
ronag
approved these changes
Feb 26, 2021
mcollina
reviewed
Feb 26, 2021
Member
Author
|
It works in the exact same way with both |
Member
|
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.
|
Member
|
FYI, you don't need to add the ProxyAgent right now. It can be another issue. |
|
is there an example with proxying a POST request? |
Member
|
No but it would be a good PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:8080didn'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