CodeVetter · Repo Unpack · Data flow
koajs/koa
Incoming Node HTTP objects remain the transport owners throughout a request. Koa adds linked wrappers, lazy parsers, and a middleware-visible state namespace. Outgoing body assignment prepares metadata, and a separate responder handles serialization or streaming.
- callback() receives req/res, constructs a context, and either invokes handleRequest directly or runs it inside ctxStorage.run(ctx).
- Context construction creates wrapper instances from application prototypes but preserves references to the original transport objects; state is allocated independently for each request.
- ctx.query reads req.url through querystring and parseurl, caches by raw query string, and uses URLSearchParams to collapse single values or retain repeated values as arrays.
- Assigning query serializes string/number values and repeated array entries; unsupported value types become empty strings before querystring updates req.url.
- Forwarded IP input is read from app.proxyIpHeader only in proxy mode, optionally right-trimmed by maxIpsCount, then memoized as ip with socket.remoteAddress fallback.
- ctx.body delegates to response.body, which stores _body and selects status, content type, length, cleanup, or Response-derived headers before transmission.
- respond() ends strings/buffers directly, converts WHATWG bodies into Node Readables for pipeline, and JSON-stringifies remaining values while recalculating byte length.
- Cookie data crosses the HTTP boundary through the cookies dependency using req/res, app.keys, and request.secure; Koa's context getter retains only the per-request cookie helper.