fix: inappropriate connection reuse when using HTTP proxy if the initial CONNECT failed #2072
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.
What This MR Resolves
A CONNECT request is needed to sent to the HTTP proxy first before the actual client request to establish the tunnel on the proxy. A
HTTP/1.1 200 Connection established
is expected for the initial CONNECT request. Only when the CONNECT is successful, the client continues sending the actual request through the "tunnel". And when CONNECT failed, the connection remains the initial stateunconnected
.There are following circumstances that a CONNECT fails under but not limited to following situations:
There could be 2 following strategies to deal with CONNECT failures on the client side:
The 2nd one needs to add extra state to Channel in the manager which brings bigger change to the code.
This MR employs the 1st strategy to resolve it. The issue is described in #2071 .
Readings
The CONNECT is documented in
Section 5.3
in RFC2871: https://www.ietf.org/rfc/rfc2817.txtThe proxy won't actively terminate the connection if the CONNECT failed if keep-alive is enabled. Unless the tunnel is established and there is any communication failures in the middle. Therefore the client needs to deal with this error by its own.