Repository navigation
Conversation
Detect already-applied patches by finding the newest patch that reverse-applies cleanly, rather than reverse-checking each patch independently. The old check broke once a later patch touched the same file as an earlier one, causing extconf to re-apply the earlier patch and abort. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add Client::preconnect and RequestBuilder::preconnect, which establish a pooled connection (TCP, proxy tunnel, TLS) without sending a request. The connection descriptor is derived the same way as for a real request, so per-request proxy and emulation options yield a reusable pool key. The scheme/https_only check and total timeout normally applied by the middleware stack are replicated, since preconnect bypasses it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Expose preconnect(url, opts = {}) to warm up a connection to an origin
without sending a request, so a later request can skip DNS, TCP, proxy
and TLS setup. Request options such as proxy, emulation and timeout are
honored so the warmed connection matches the later request. The call
releases the GVL and is interruptible via cancel and thread interrupts.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Adds
preconnect, which opens a connection to an origin ahead of time without sending a request. It does the DNS lookup, TCP connect, proxy tunnel and TLS handshake, then leaves the connection idle in the client's pool. The next request to that origin reuses it and skips connection setup.Behaviour
preconnectbuilds its pool key the same way a real request does, soproxy:andemulation:(plusemulation_os:etc.) must match the later request for the connection to be reused. Other request options are ignored.timeout:limits how long the preconnect can take; otherwise the client's timeout and connect timeout apply.CONNECTtunnel with TLS inside it.canceland Ruby thread interrupts abort it.preconnectdoes nothing withpool_max_idle_per_host: 0.Implementation
patches/0002-add-preconnect.patch):Client::preconnect(uri)andRequestBuilder::preconnect().HttpClient's request setup is split into a sharedprepare(), so preconnect and real requests compute the pool key the same way.preconnectasks the pool for a connection and drops it straight away, which puts it back as idle. HTTP/1 connections are already awaited until ready before being handed out, so the dropped connection is reusable.https_onlycheck and the total timeout.Client#preconnect(url, opts = {})uses the same option handling and cancellation pattern as the request methods.extconf.rb: patch detection now handles stacked patches. Before, each patch was reverse-checked on its own, so once0002touchedsrc/client.rs(also changed by0001),0001looked unapplied and the build aborted. Now it finds the newest patch that reverse-applies cleanly and treats it and every earlier patch as applied.Testing
test/preconnect_test.rb, mostly against a local keep-alive server. It checks that:timeout:is enforced;rake test) passes on a clean checkout of the branch, with both patches applied from scratch byextconf.rb.CONNECTproxy. With both a per-request and a client-level proxy, preconnect opened one tunnel and the nextgetreused it.https://www.google.com/generate_204, 8 runs: median coldgetabout 650 ms, versus about 170 ms for agetafter preconnect.Not covered
preconnectfrom separate threads.