12345module juptune.http.v1;
Result readBody(
Http1BodyChunk bodyChunk
);
Reads a single chunk of body data.
This function must be called when the reader is in the bodystate.
[Requests Only] After this function is called, the reader will be in the bodystate if there's more data to read, or the finalisestate if there's no more data to read.
[Responses Only] After this function is called, the reader will be in the bodystate if there's more data to read, or the maybeEndOfTrailersstate if there's no more data to read.
This is intended to be a helper function used to read body data in a unified way, regardless of the body encoding for those that do not need nor care about having encoding-specific logic.
Currently lower-level access to the body data is not provided, but will be in the future.
This function makes use of the user buffer to determine the maximum amount of bytes that can be stored at once. In the future an overload that allows the user to provide a separate buffer will be provided.
If the body is chunked, then the reader will automatically handle the chunking.
If the body is chunked, a small quirk is that the reader will return an empty data slice when the "empty marker" chunk is reached, and only the next read will return falsefor hasDataLeft.
In order to simplify the user code, the reader will always transition responses to the maybeEndOfTrailersstate, even if the response is not using chunked transfer-encoding.
If an error occurs, the reader will be in an invalid state and should not be used again.
Anything the underlying I/O functions can throw. See juptune.event.io.IoError.
Http1Error.badBodyChunkif the body is chunked and the client sent an invalid chunk.
Http1Error.badBodyChunkSizeif the body is chunked and the client sent an invalid chunk size.
Http1Error.badTransportif it is determined that the transport layer is in a bad state, or if the sender appears to be malicious/poorly coded.
A Resultdescribing if an error ocurred. Any Http1Errorwill contain a valid HTTP error response that can be sent to the client as-is.