Minor Changes
-
Start Node.js HTTP and HTTPS servers with managed socket lifecycle and graceful shutdown using the new
serve()helper, modeled afterBun.serve(). Callingserver.stop()stops accepting new connections, closes idle and speculative zero-byte TCP/TLS sockets immediately, and waits for in-flight requests to finish; callingserver.stop(true)closes all active connections immediately or escalates an in-progress graceful stop. (#12491)import * as fs from 'node:fs' import { serve } from '@remix-run/node-fetch-server' let server = await serve({ port: 3000, fetch(request) { return new Response(`Hello from ${new URL(request.url).pathname}`) }, }) // Graceful drain, or pass `true` to close active connections immediately await server.stop() // Pass `tls` options to serve over HTTPS using `node:https` let secureServer = await serve({ port: 443, fetch(request) { return new Response(`Secure: ${request.url}`) }, tls: { key: fs.readFileSync('private-key.pem'), cert: fs.readFileSync('certificate.pem'), }, })
createTestServer()in@remix-run/node-fetch-server/testnow usesserve()under the hood so test servers close lingering connections immediately on teardown.
Patch Changes
-
HTTP/2 responses now omit connection-specific headers, including fields named by
Connectionwithin the same set of response headers. If the request listener cannot send an error response, it logs the write failure and closes the affected response. (#12484) -
Improve request and response handling throughput in
createRequestListener(),createRequest(), andsendResponse(). As part of this change,sendResponse()no longer releases its reader lock on the consumedresponse.bodystream after writing, bodyless HTTP/1.x requests (withContent-Length: 0or neitherContent-LengthnorTransfer-Encoding) now leaverequest.bodyasnullinstead of wrapping an empty stream, andcreateRequestListener()now always constructs and passes aRequestto handlers with.length === 0(such as rest-parameter handlers) and routes their errors throughonErrorconsistently with other handlers. (#12450) -
Reject incoming requests with a literal backslash (
\) in the URL path.createRequestListener()responds with400 Bad RequestunlessonErrorreturns a custom response, andcreateRequest()throws. Percent-encoded backslashes (%5C) and backslashes in the query string are still accepted. (#12368) -
Finish single-chunk responses that include a matching
Content-Lengthheader directly withres.end(chunk)instead of callingres.write()followed by a separateres.end(). (#12463)