-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
ResponseBuilder is a plain fluent builder — every method returns the same builder type, so finish_headers() is always reachable regardless of which headers you've actually set. That means callers can build a complete response without ever setting Content-Length, and the compiler won't say a word about it.
I hit this in hobby (ponylang/hobby#36). respond_with_headers passes caller-provided headers straight through to ResponseBuilder, and if the caller forgets Content-Length, the response silently relies on connection-close semantics to signal end-of-body. The simpler respond() auto-computes it, but the moment you need a custom header, you're on your own.
The fix on the hobby side is to auto-add Content-Length when the caller omits it. That works, but the root cause is here: ResponseBuilder doesn't enforce that required headers are present before you can finish.
If ResponseBuilder used the typed-step builder pattern, there'd be a phase type that requires Content-Length (or an explicit opt-out for chunked encoding) before finish_headers() is reachable. The omission becomes a compile error instead of a silent protocol violation.