HTTPure.Body
- Package
- purescript-httpure
- Repository
- citizennet/purescript-httpure
#Body Source
class Body b whereTypes that implement the Body class can be used as a body to an HTTPure
response, and can be used with all the response helpers.
Members
defaultHeaders :: b -> Effect Headerswrite :: b -> Response -> Aff UnitGiven a body value and a Node HTTP
Responsevalue, write the body value to the Node response.
Instances
Body StringThe instance for
Stringwill convert the string to a buffer first in order to determine it's additional headers. This is to ensure that theContent-Lengthheader properly accounts for UTF-8 characters in the string. Writing is simply implemented by writing the string to the response stream and closing the response stream.Body BufferThe instance for
Bufferis trivial--we add aContent-Lengthheader usingBuffer.size, and to send the response, we just write the buffer to the stream and end the stream.(TypeEquals (Stream r) (Readable s)) => Body (Stream r)This instance can be used to send chunked data. Here, we add a
Transfer-Encodingheader to indicate chunked data. To write the data, we simply pipe the newtype-wrappedStreamto the response.
#read Source
read :: Request -> Effect RequestBodyRead the body Readable stream out of the incoming request
#toBuffer Source
toBuffer :: RequestBody -> Aff BufferTurn RequestBody into a Buffer
This drains the Readable stream in RequestBody for the first time
and returns cached result from then on.
#toStream Source
toStream :: RequestBody -> Readable ()Return the Readable stream directly from RequestBody
Return any default headers that need to be sent with this body type, things like
Content-Type,Content-Length, andTransfer-Encoding. Note that any headers passed in a response helper such asok'will take precedence over these.