@@ -50,12 +50,23 @@ data GzipSettings = GzipSettings
5050 , gzipCheckMime :: S.ByteString -> Bool
5151 }
5252
53−data GzipFiles = GzipIgnore | GzipCompress | GzipCacheFolder FilePath
53+-- | Gzip behavior for files.
54+data GzipFiles
55+ = GzipIgnore -- ^ Do not compress file responses.
56+ | GzipCompress -- ^ Compress files. Note that this may counteract
57+ -- zero-copy response optimizations on some
58+ -- platforms.
59+ | GzipCacheFolder FilePath -- ^ Compress files, caching them in
60+ -- some directory.
5461 deriving (Show, Eq, Read)
5562
63+-- | Use default MIME settings; /do not/ compress files.
5664instance Default GzipSettings where
5765 def = GzipSettings GzipIgnore defaultCheckMime
5866
67+-- | MIME types that will be compressed by default:
68+-- @text/*@, @application/json@, @application/javascript@,
69+-- @application/ecmascript@, @image/x-icon@.
5970defaultCheckMime :: S.ByteString -> Bool
6071defaultCheckMime bs =
6172 S8.isPrefixOf "text/" bs || bs' `Set.member` toCompress
@@ -73,9 +84,7 @@ defaultCheckMime bs =
7384-- Analyzes the \"Accept-Encoding\" header from the client to determine
7485-- if gzip is supported.
7586--
76−-- Possible future enhancements:
77−--
78−-- * Only compress if the response is above a certain size.
87+-- File responses will be compressed according to the 'GzipFiles' setting.
7988gzip :: GzipSettings -> Middleware
8089gzip set app env sendResponse = app env $ \res ->
8190 case res of