Commits

Luke Plant  committed 53e9a7c

Added utility for empty responses which are text but not 'text/plain'

  • Participants
  • Parent commits 989ac7d

Comments (0)

Files changed (2)

File src/Ella/Request.hs

 -- PATH_INFO and other vars contains Haskell Strings, but in reality these are
 -- simply the bytes obtained from the environment packed into Unicode chars one
 -- byte at a time.  We re-pack them into a ByteString (pack discards anything
--- > \255, which includes nothing in this case), and then re-interpret.
+-- greater than \255, which includes nothing in this case), and then re-interpret.
 repack :: String -> Encoding -> String
 repack str encoding = let bytes = pack str
                       in (decoder encoding) bytes

File src/Ella/Response.hs

                     , utf8TextResponse
                     , htmlResponse
                     , utf8HtmlResponse
+                    , textBasedResponse
                     , emptyResponse
                     , redirectResponse
                     -- * Using Response objects
 -}
 
 contentTypeName = HeaderName "Content-type"
-textContent charset = "text/plain; charset=" ++ charset
-htmlContent charset = "text/html; charset=" ++ charset
+contentTypeValue mimetype charset = mimetype ++ "; charset=" ++ charset
+textContent charset = contentTypeValue "text/plain" charset
+htmlContent charset = contentTypeValue "text/html" charset
+
+-- | An empty response of the given mimetype and charset.
+textBasedResponse :: String -> String -> Response
+textBasedResponse mimetype charset = emptyResponse {
+                                       headers = [(contentTypeName, contentTypeValue mimetype charset)]
+                                     }
 
 -- | An empty text/plain response of a given charset
 textResponse :: String -> Response