hack-middleware-gzip (empty) → 0.0.0
raw patch · 4 files changed
+94/−0 lines, 4 filesdep +basedep +hackdep +splitsetup-changed
Dependencies added: base, hack, split, zlib
Files
- Hack/Middleware/Gzip.hs +44/−0
- LICENSE +25/−0
- Setup.lhs +7/−0
- hack-middleware-gzip.cabal +18/−0
+ Hack/Middleware/Gzip.hs view
@@ -0,0 +1,44 @@+---------------------------------------------------------+-- |+-- Module : Hack.Middleware.Gzip+-- Copyright : Michael Snoyman+-- License : BSD3+--+-- Maintainer : Michael Snoyman <michael@snoyman.com>+-- Stability : Unstable+-- Portability : portable+--+-- Automatic gzip compression of responses.+--+---------------------------------------------------------+module Hack.Middleware.Gzip (gzip) where++import Hack+import Codec.Compression.GZip (compress)+import Data.Maybe (fromMaybe)+import Data.List.Split (splitOneOf)++-- | Use gzip to compress the body of the response.+--+-- Analyzes the \"Accept-Encoding\" header from the client to determine+-- if gzip is supported.+--+-- Possible future enhancements:+--+-- * Only compress if the response is above a certain size.+--+-- * Add Content-Length.+--+-- * I read somewhere that \"the beast\" (MSIE) can\'t support compression+-- for Javascript files..+gzip :: Middleware+gzip app env = do+ res <- app env+ let enc = fromMaybe [] $ splitOneOf "," `fmap` lookup "Accept-Encoding"+ (http env)+ if "gzip" `elem` enc+ then return res+ { body = compress $ body res+ , headers = ("Content-Encoding", "gzip") : headers res+ }+ else return res
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2008, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ hack-middleware-gzip.cabal view
@@ -0,0 +1,18 @@+name: hack-middleware-gzip+version: 0.0.0+license: BSD3+license-file: LICENSE+author: Michael Snoyman <michael@snoyman.com>+maintainer: Michael Snoyman <michael@snoyman.com>+synopsis: Automatic gzip compression of responses.+category: Web+stability: unstable+cabal-version: >= 1.2+build-type: Simple+homepage: http://github.com/snoyberg/hack-middleware-gzip/tree/master++library+ build-depends: base >= 3, split >= 0.1.1, zlib >= 0.5,+ hack >= 2009.5.19+ exposed-modules: Hack.Middleware.Gzip+ ghc-options: -Wall