Module

HTTPure.Body

#Body

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

    Return any default headers that need to be sent with this body type, things like Content-Type, Content-Length, and Transfer-Encoding. Note that any headers passed in a response helper such as ok' will take precedence over these.

  • 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 the Content-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 a Content-Length header using Buffer.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-wrapped Stream to the response.

#read

read :: Request -> Aff String

Extract the contents of the body of the HTTP Request.

Modules