packages feed

webserver 0.7.1.0 → 0.7.1.1

raw patch · 2 files changed

+19/−3 lines, 2 filesdep +zlib

Dependencies added: zlib

Files

Network/Web/Server/Basic.hs view
@@ -14,6 +14,7 @@                                  basicServer,                                  module Network.Web.Server.Params) where +import qualified Codec.Compression.GZip as GZip import Control.Applicative import Control.Concurrent (forkIO) import Control.Concurrent.MVar@@ -248,7 +249,9 @@       case mst of         Just OK -> do           val <- obtain cnf file' Nothing-          return . Just $ response OK val size ct modified+          return . Just $ if isGzipRequest req+            then responseGzip OK val ct modified+            else response OK val size ct modified         Just st@(PartialContent skip len) -> do           val <- obtain cnf file' $ Just (skip,len)           let rangeSpec = S.pack $ printf "bytes %d-%d/*" skip (skip+len-1)@@ -288,6 +291,12 @@   Nothing         -> Just RequestedRangeNotSatisfiable   Just (skip,len) -> Just (PartialContent skip len) +isGzipRequest :: Request -> Bool+isGzipRequest req = do+    case lookupField FkAcceptEncoding req of+        Just codings -> any (== "gzip") [ S.takeWhile (/= ';') c | c <- S.split ',' codings ]+        _            -> False+ ----------------------------------------------------------------  tryHead :: BasicConfig -> Request -> [String] -> IO (Maybe Response)@@ -364,6 +373,13 @@ response st val len ct modified = makeResponse2 st (Just val) (Just len) kvs   where     kvs = [(FkContentType,ct),(FkLastModified,modified)]++responseGzip :: Status -> L.ByteString -> CT -> HttpDate -> Response+responseGzip st val ct modified = makeResponse2 st (Just bytes) (Just len) kvs+  where+    bytes = GZip.compress val+    len = fromIntegral (L.length bytes)+    kvs = [(FkContentType,ct),(FkLastModified,modified),(FkContentEncoding,"gzip")]  ---------------------------------------------------------------- 
webserver.cabal view
@@ -1,5 +1,5 @@ Name:                   webserver-Version:                0.7.1.0+Version:                0.7.1.1 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             John W. Lato <jwlato@gmail.com> License:                BSD3@@ -27,7 +27,7 @@   Build-Depends:        base >= 4 && < 5, parsec >= 3,                         network, directory, bytestring, containers, old-locale,                         stm,-                        filepath, time, unix, process, c10k+                        filepath, time, unix, process, c10k, zlib Source-Repository head   Type:                 git   Location:             git://github.com/JohnLato/webserver.git