@@ -50,12 +50,23 @@ data GzipSettings = GzipSettings
50 , gzipCheckMime :: S.ByteString -> Bool
50 , gzipCheckMime :: S.ByteString -> Bool
53+-- | Gzip behavior for files.
55+ = GzipIgnore -- ^ Do not compress file responses.
56+ | GzipCompress -- ^ Compress files. Note that this may counteract
57+ -- zero-copy response optimizations on some
53−data GzipFiles = GzipIgnore | GzipCompress | GzipCacheFolder FilePath
59+ | GzipCacheFolder FilePath -- ^ Compress files, caching them in
54 deriving (Show, Eq, Read)
61 deriving (Show, Eq, Read)
63+-- | Use default MIME settings; /do not/ compress files.
56instance Default GzipSettings where
64instance Default GzipSettings where
57 def = GzipSettings GzipIgnore defaultCheckMime
65 def = GzipSettings GzipIgnore defaultCheckMime
67+-- | MIME types that will be compressed by default:
68+-- @text/*@, @application/json@, @application/javascript@,
69+-- @application/ecmascript@, @image/x-icon@.
59defaultCheckMime :: S.ByteString -> Bool
70defaultCheckMime :: S.ByteString -> Bool
60defaultCheckMime bs =
71defaultCheckMime bs =
61 S8.isPrefixOf "text/" bs || bs' `Set.member` toCompress
72 S8.isPrefixOf "text/" bs || bs' `Set.member` toCompress
@@ -73,9 +84,7 @@ defaultCheckMime bs =
73-- Analyzes the \"Accept-Encoding\" header from the client to determine
84-- Analyzes the \"Accept-Encoding\" header from the client to determine
74-- if gzip is supported.
85-- if gzip is supported.
76−-- Possible future enhancements:
87+-- File responses will be compressed according to the 'GzipFiles' setting.
78−-- * Only compress if the response is above a certain size.
79gzip :: GzipSettings -> Middleware
88gzip :: GzipSettings -> Middleware
80gzip set app env sendResponse = app env $ \res ->
89gzip set app env sendResponse = app env $ \res ->
81 case res of
90 case res of