| 1 | # 0002 — The transport layer takes streams, not `Request`/`Response` |
| 2 | |
| 3 | **Status:** adopted |
| 4 | |
| 5 | ## Decision |
| 6 | |
| 7 | `GitService` and everything below it accept `Readable` and return |
| 8 | `{ headers, body }`. Only `GitController` knows `Request |
| 9 | |
| 10 | ```ts |
| 11 | async receivePack({ username |
| 12 | ``` |
| 13 | |
| 14 | ## Why |
| 15 | |
| 16 | Git is a streaming protocol, so a service that cannot stream is useless. But |
| 17 | `req` fuses two things: a byte stream, and an HTTP envelope (params, query, |
| 18 | status, header setters). The service needs the stream. The controller owns |
| 19 | the envelope. |
| 20 | |
| 21 | `Readable` is a Node type, not an HTTP type. Express's request *is* |
| 22 | so the controller passes `req` directly and the type narrows to the stream half. |
| 23 | Nothing inside the service can reach `req.params`. |
| 24 | |
| 25 | Headers are **returned as data**, never set. If the service called |
| 26 | `res.setHeader` it would be HTTP-bound again. Returning a plain object means a |
| 27 | test asserts on `headers['Content-Type']` with no server anywhere. |
| 28 | |
| 29 | ## The ordering bug this fixed |
| 30 | |
| 31 | The original `infoRefs` wrote the pkt-line service header to the socket *before |
| 32 | it knew the spawn would succeed. Because headers are now returned rather than |
| 33 | written, validation and path resolution both complete before anything touches |
| 34 | the socket — which is why the dumb-protocol rejection can be a thrown |
| 35 | `DomainError` at all (see [0005]( |
| 36 | principle applied to durability). |
| 37 | |
| 38 | ## Consequences |
| 39 | |
| 40 | - `git.service.spec.ts` runs with no server, no port, and no `git` binary. |
| 41 | - `PackProcessService` can be tested for real against a `git init --bare` tmpdir, |
| 42 | driven by `Readable.from(buffer)`. |
| 43 | - `@Res()` appears exactly once per handler and does exactly one thing. |