Fix keepAlive for http-proxy-agent#169
Closed
jportner wants to merge 8 commits intoTooTallNate:mainfrom
Closed
Conversation
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.
I was testing the new
keepAliveoption, and it turns out that while it works for https-proxy-agent, it doesn't work with http-proxy-agent.I use Smokescreen, and when testing keepAlive with http-proxy-agent, the first request succeeded, but all subsequent requests failed with an error: "This is a proxy server. Does not respond to non-proxy requests"
Turns out, the first request used an absolute URL (
http://localhost:3000/foo) while all subsequent requests used relative URLs (/foo). HTTP proxy servers require that HTTP requests use absolute URLs, which is why this happens. (HTTPS requests are not impacted because they are encrypted, and regular non-MITM proxies cannot read the URL).The http-proxy-agent package already had logic to rewrite the relative URL to an absolute URL:
proxy-agents/packages/http-proxy-agent/src/index.ts
Lines 88 to 90 in 2f835a4
However, that only happens on
connect(), so it only worked on the first request. This PR makes the following changes: