HTTP/2 client inside HTTP/1.1 proxy connection #3613
-
I want to open a connection to proxy server and then establish H2 connection inside first one to target server. I know, that import { Client, ProxyAgent, request } from 'undici';
const test = async () => {
try {
const proxy = new ProxyAgent({
uri: `http://host:port`,
token: `Basic ${Buffer.from(`user:pass`).toString('base64')}`,
// allowH2: true // not working because proxy server seems not handle H2
});
const h2Client = new Client('https://api.ipify.org', {
allowH2: true,
// connect: {
// rejectUnauthorized: false,
// ...(await proxy.connect({ origin: 'http://host:port', path: '/' })), // not working
// },
});
const { body, statusCode } = await request(
`https://api.ipify.org?format=json`,
{
dispatcher: h2Client,
}
);
console.log(statusCode);
const data = await body.json();
console.log(data);
} catch (e) {
console.log(e);
}
};
await test(); I also tried to implement following answer using undici but didn't get the result. |
Beta Was this translation helpful? Give feedback.
Answered by
metcoder95
Sep 19, 2024
Replies: 1 comment 8 replies
-
Do you have the error that is thrown when attempting to connect? |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, see what you mean. Here what you want to do is to first connect to the Proxy and use that socket to do the requests in the second agent/dispatcher.
What I was suggesting was not to use the Agent and have an internal
connect
that goes to a Proxy, but actually the other way around.On the
ProxyAgent
you pass a custom connect that connects to the proxy with H1 (using an Agent) and returns that socket to theconnect
callback so it can be reused across request. Similar to what ProxyAgent does to connect to the Proxy.