hack-2009.4.25: src/Hack/Contrib/ContentSize.hs
module Hack.Contrib.ContentSize where
import Hack
import Hack.Utils
import Hack.Response
import Hack.Constants
import MPSUTF8
import Prelude hiding ((.), (^), (>))
import Data.Maybe
content_size :: MiddleWare
content_size app = \env -> do
response <- app env
if should_size response
then response
.set_header _ContentLength (response.body.bytesize.show) .return
else response .return
where
should_size response =
[ not $ response.has_header _ContentLength
, not $ response.has_header _TransferEncoding
, not $ status_with_no_entity_body.has(response.status)
] .and