mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-03 07:54:40 +08:00
The native fetch dialed a new connection for every request and closed it after the response, so a loop of requests to one origin paid a TCP connect, and for https a TLS handshake, per request. Node's fetch keeps connections alive through undici's dispatcher. A direct request now goes through a keep-alive agent private to fetch (scr_http_fetch_request): an idle connection for the same host, port and bare hostname serves the next request, there is no limit on connections per origin, and an idle connection closes after 4 s or the server's Keep-Alive hint less one second, without keeping the process alive. Proxied requests still dial their own connection. When a response ends, the transfer resumes its socket if it had paused it and stops pausing and resuming it, since the agent may hand the socket to the next request. scr_http_request_agent_ex and http.Agent creation share their agent logic with the new entry point.