# Network transport

The workspace API performs one HTTP exchange through `with_response`.
`Request` contains the resolved target, Host field, method, final headers and
body. `Transport` contains only proxy/TLS settings, connection and inactivity
limits, and an optional absolute monotonic deadline. Commands own preparation
and subsequent requests. This intentional source API change is unpublished;
the immutable registry coordinates retain their original interfaces.

`ResponseScope` exposes the final status and ordered fields and reads bounded
body chunks. It closes the connection on normal return, error and observable
cancellation. Explicit close is idempotent; reading an escaped closed scope
fails. Body bytes are never accumulated into a whole-response buffer.

## Wire mechanisms

The connection owner uses released public TCP/TLS APIs and retains structured
canonical hosts for DNS, SNI and proxy CONNECT. The HTTP/1 parser accepts
HTTP/1.0 and HTTP/1.1 and supports fixed-length, chunked, close-delimited and
bodyless responses. It delivers chunk payload before validating the following
separator, preserving bytes already observed before a later framing failure.
CONNECT uses a one-byte read bound to avoid consuming tunneled bytes.

Response metadata is bounded to 65536 bytes per line, 1 MiB of cumulative
headers, 1024 fields per header/trailer block and 128 interim responses.
Invalid header names, conflicting framing and unsupported transfer codings
fail explicitly. Final request fields are validated before writing, including
any fields generated by command policy. File and stdin request bodies stream
through the existing bounded loops. Content coding is not decoded.

Incomplete final headers expose `complete=false` and only complete fields.
An incomplete body exposes the precise boundary: fixed payload, chunk payload,
size line, separator or trailers. A command decides whether its compatibility
contract accepts that observation. The transport has no Curl/Wget profile
switch and does not apply a default command EOF policy.

Transport errors retain the connection/request/header/body phase, response
framing, completed upload bytes and reader-delivered bytes. Command output
owners enrich the shared error context with completed writes and uncertain
write effects. A failed Writer call can have effects that its public API does
not report; the committed count remains a lower bound.

## Ownership

Both commands use the common URL structure, IDNA implementation and pinned
ICANN/PRIVATE public-suffix data. URL input/redirect spelling, proxy matching,
Cookie admission/order/persistence, credentials, challenge replay, redirects,
retries, resume, filenames, output commitment and diagnostics belong to
[`curl/internal/download`](../../commands/curl/internal/download/) and
[`wget/internal/download`](../../commands/wget/internal/download/).

Curl retains deferred ordinary file opening and 4096-byte commits, exclusive
Content-Disposition destinations and its primary-error precedence. Wget retains
immediate writes, numbered destinations, retry offsets and distinct EOF rules.
Their private implementations and tests move together; neither imports the
other command's internal package. Small dialect adaptations may be duplicated.
The former `transfer`, `TransferOptions`, profiles and Cookie API are removed
from core without forwarding shims. See [ADR-0005](../../docs/adr/0005-transfer.md)
for the command contracts, including remaining proxy and pathname limitations.

## Verification

`exchange_wbtest.mbt` exercises bounded delivery, exact EOF boundaries, upload
and receive error context, and connection closure on return/error/cancellation.
Wire grammar, IDNA and public-suffix tests remain beside their mechanisms.
Command packages own Cookie/date/number tables, authentication and output state
tests, including all original 594 Cookie records and 73 authentication records.
Missing fixtures and invalid/duplicate record identities fail.

The existing [network scenarios](../../tests/scenarios/network/) retain real
Wasm process, request, file, retry, cancellation and cleanup effects. Complete
dense CLI corpora remain available for required fixed-oracle differential and
independent frozen published acceptance. Package tests do not establish full
upstream parity or formal performance acceptance.
