Description
Background
Recently, we accepted a PR from dependabot bumping proxy-agent
from 4.0.1
to 5.0.0
. Due to passing CI and no concerns after reading the release notes, we merged it.
It sparked a discussion amongst maintainers where we asked ourselves: why do we have proxy-agent?
The goal of this issue is to investigate our use and see if it's still needed in the codebase.
Investigation
What is proxy-agent
?
an npm
package which:
Maps proxy protocols to http.Agent implementations
What is a proxy protocol?
There are two parts to understanding this. First, let's discuss what we mean by proxy.
proxy: an interface to something else.
e.g. let's say you have a basic React app that needs to talk to a weather API. It requires an API key, which you don't want to expose on the client because then anyone could see and use it. You might use a proxy which could be a serverless function, a server, etc. which has access to the API key and passes on your request to the weather API.
Second, let's discuss what we mean by protocol.
protocol: a set of rules and guidelines for communicating data.
e.g. HTTP stands for "Hypertext Transfer Protocol" and is the stand for how data should be communicated on the web.
Now that we're on the same page for those two words, I bet you can guess what we mean by "proxy protocol".
proxy protocol: a set of rules and guidelines for communicating data between proxies
What is an http.Agent
?
We can read about http.Agent
which is a class in Node.js. Agent
is defined as:
An Agent is responsible for managing connection persistence and reuse for HTTP clients. It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to the same host and port.
Source: Node.js docs
That definition feels a bit hard to understand IMO. Looking at this StackOverflow question, the OP explains it as:
an Agent is 'in charge' of managing a connection - and clearly, the fact that https.Agent exists on top of the 'plain' http.Agent exists would imply that it is 'in charge' of managing an HTTPS connection
which helps a little bit but I'm still a little unsure.
Spoke to @jawnsy who gave a couple analogies.
An agent is kind of like a controller in charge of managing a pool of TCP connections. A TCP connection is a "reliable" connection that tracks packets of data as they're sent and received. It's like sending a letter to a friend, you tell the friend you didn't get all of the letter so they send another copy.
When was it added?
It was added in #2400 to resolve #124. There is a lot of history in the commit messages from the developer who implemented this.
What do we use it for?
It's used in src/node/proxy_agent.ts
.
@jawnsy also managed that this package "handles using an HTTP proxy, which is required in some environments (e.g. sometimes companies force all outbound web traffic to go through a single point, so that it can be better controlled and monitored)" which I am guessing is similar to how we use it.
We use it to support $HTTP_PROXY
, $HTTPS_PROXY
and $NO_PROXY
.
This was needed in order to support #124
vscode use http_proxy and https_proxy environment variables if the proxy setting not set.
Can we remove it?
I think before we do, we should probably have tests to make sure this behavior is working correctly so that whatever we migrate to still works after we remove proxy-agent
.
If we do, I think we'll need to set up a proxy then point HTTP_PROXY
to it and ensure all requests go through it (especially extension requests).
If no, explain what we should do instead:
- document use somewhere
- write tests for code that uses it