Skip to content

proxyFetch(): option to keep the upstream Node.js stream as the response body #185

Closed

Description

@pi0x

proxyFetch() converts the upstream IncomingMessage into a web stream (Readable.toWeb(res)). When the result is served by a Node server, srvx's Node adapter for example, the body is then read back chunk by chunk from that web stream. A Node-to-Node proxy pays two stream conversions per response.

srvx's Node adapter pipes a Node.js stream body natively, and so does srvx's FastResponse (NodeResponse), which accepts one as body. If proxyFetch() could return the IncomingMessage itself as the body, that path would avoid both conversions.

Use case: env-runner proxies every request from the host to its worker with proxyFetch() (runner.fetch()), and RunnerManager already tracks Node.js stream bodies (unjs/env-runner#92).

Possible shapes (httpxy has no srvx dependency, so it would be opt-in):

  • an option to supply the response constructor, e.g. proxyFetch(addr, req, init, { Response: FastResponse }), with the IncomingMessage passed as the body
  • or an option to return the raw IncomingMessage (status, headers, stream) and let the caller build the response

Opened with AI assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions