HTTPure.Body
- Package
- purescript-httpure
- Repository
- citizennet/purescript-httpure
#Body Source
class Body b where
Types 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 Headers
write :: b -> Response -> Aff Unit
Given a body value and a Node HTTP
Response
value, write the body value to the Node response.
Instances
Body String
The instance for
String
will convert the string to a buffer first in order to determine it's additional headers. This is to ensure that theContent-Length
header 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 Buffer
The instance for
Buffer
is trivial--we add aContent-Length
header 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-Encoding
header to indicate chunked data. To write the data, we simply pipe the newtype-wrappedStream
to the response.
#read Source
read :: Request -> Effect RequestBody
Read the body Readable
stream out of the incoming request
#toBuffer Source
toBuffer :: RequestBody -> Aff Buffer
Turn 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.