HTTPure.Body
- Package
- purescript-httpure
- Repository
- cprussin/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 ())) => 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.
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.