Add H1 same-connection redirect follow-up#867
Closed
kursadaltan wants to merge 3 commits intocloudflare:mainfrom
Closed
Add H1 same-connection redirect follow-up#867kursadaltan wants to merge 3 commits intocloudflare:mainfrom
kursadaltan wants to merge 3 commits intocloudflare:mainfrom
Conversation
dd72ae4 to
0d80c66
Compare
Avoid noisy warnings when a synthetic 3xx is used for the redirect follow-up hop (context prefix redirect_follow_hop:). Made-with: Cursor
0d80c66 to
7b06bda
Compare
Updated the reuse_hash method in BasicPeer to incorporate the SNI when TLS is used, ensuring distinct connection reuse for different hostnames on the same IP:port. This change maintains historical behavior when SNI is empty (non-TLS).
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.
Summary
Adds Session::h1_set_same_connection_followup so user code can follow an HTTP/1.1 upstream redirect (e.g. 3xx) on the same pooled upstream connection: the intermediate response body is consumed without writing it to the client, then a follow-up request is issued on that connection via an internal loop in proxy_to_h1_upstream. This avoids the pattern of returning Err from response_filter and relying on the outer process_request retry loop, which drops upstream keep-alive (client_reuse == false and no release_http_session on that path).
Related issue: #866
Motivation
Following redirects by erroring out of response_filter causes proxy_1to1 to fail try_join! and return client_reuse = false, so each retry opens a new upstream connection. At scale this hurts latency and connection reuse. RFC-aligned behavior for H/1 is to drain the redirect response on the same TCP connection when the next hop is the same origin, then send the next request on that connection.
What changed
Session: optional follow-up RequestHeader, flag to skip writing the current upstream response downstream, and h1_set_same_connection_followup (disables cache for the skipped hop when caching is enabled).
proxy_to_h1_upstream: loops while a follow-up is scheduled after a successful proxy_1to1 leg.
process_upstream_tasks: when skipping downstream for the current response, does not forward response tasks to the client while the upstream side still drains the body through the filter chain.
Docs: ProxyHttp::response_filter points to the new API.
CHANGELOG: Unreleased entry.
Unit test for the follow-up / skip behavior.
Usage (conceptual)
From response_filter, on an intermediate response you choose to follow on the same connection, build the next RequestHeader and call session.h1_set_same_connection_followup(request) and return Ok(()). Do not use this for untrusted cross-origin redirects without validating Location in application code.
Testing
cargo test -p pingora-proxy --lib