httpaf
httpaf copied to clipboard
Surface write failures through [flush]
Currently, if you are writing to a body in a streaming manner, and the writer becomes closed, then you have to be careful to not write any more to the body. In practice this can be hard to achieve because your application-level code is probably the one writing to the body and your runtime / network-level code is the one that calls report_write_result `Closed
.
This PR therefore makes it safe to write to a body after the attached writer is closed. Those writes are simply ignored.
The user has two ways of discovering whether their writes are actually going to be processed or not:
- They can look at
Body.is_closed
, which now returns true if we've detected that the attached writer is closed, in addition to returning true ifBody.closed
has been called. - The type of
Body.flush
has been augmented so that the callback is told whether the bytes successfully made it out of the writer, or were dropped on the floor. I.e. it has typeval Body.flush : Body.t -> ([ `Closed | `Written ] -> unit) -> unit
.