module Hack.Contrib.Middleware.ContentSize (content_size) where import Hack import Hack.Contrib.Utils import Hack.Contrib.Response import Hack.Contrib.Constants import MPSUTF8 import Prelude hiding ((.), (^), (>)) 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