on master help sign in
warp-tls: take instead of takeMost
commit925181946427f4c945e5792b6c280064b0c3acfd authorMichael Snoyman <michael@snoyman.com> dateThu 21 Mar 2013, 10:03 (14 years ago) parenta602495
2 files changed+3−12
warp-tls/Network/Wai/Handler/WarpTLS.hs+2−11 warp-tls/warp-tls.cabal+1−1
warp-tls/Network/Wai/Handler/WarpTLS.hs+2−11
@@ -38,6 +38,7 @@ import Control.Monad (unless)
3838import Crypto.Random.API (getSystemRandomGen)
3939import Control.Exception (Exception, throwIO)
4040import Data.Typeable (Typeable)
41+import qualified Data.Conduit.Binary as CB
4142
4243data TLSSettings = TLSSettings
4344 { certFile :: FilePath
@@ -104,7 +105,7 @@ runTLSSocket TLSSettings {..} set sock app = do
104105 { TLS.backendFlush = return ()
105106 , TLS.backendClose = return ()
106107 , TLS.backendSend = \bs -> C.yield bs C.$$ toClient
107− , TLS.backendRecv = getNext . takeMost
108+ , TLS.backendRecv = getNext . fmap (B.concat . L.toChunks) . CB.take
108109 }
109110 params
110111 gen
@@ -177,13 +178,3 @@ readPrivateKey filepath = do
177178 where parseKey (Right pems) = map (fmap (TLS.PrivRSA . snd) . KeyRSA.decodePrivate . L.fromChunks . (:[]) . PEM.pemContent)
178179 $ filter ((== "RSA PRIVATE KEY") . PEM.pemName) pems
179180 parseKey (Left err) = error $ "Cannot parse PEM file: " ++ err
180−
181−takeMost :: Monad m => Int -> C.Sink B.ByteString m B.ByteString
182−takeMost i =
183− C.await >>= maybe (return B.empty) go
184− where
185− go bs = do
186− unless (B.null y) $ C.leftover y
187− return x
188− where
189− (x, y) = B.splitAt i bs
warp-tls/warp-tls.cabal+1−1
@@ -1,5 +1,5 @@
11Name: warp-tls
2−Version: 1.4.0
2+Version: 1.4.0.1
33Synopsis: SSL support for Warp via the TLS package
44License: MIT
55License-file: LICENSE