Last active
August 29, 2015 14:26
-
-
Save Porges/153837bd72ccc739da8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listContainers :: HTTP.Manager -> AccountName -> P.Producer ByteString IO () | |
listContainers manager account = do | |
req <- P.lift $ fillOutTemplate template -- does some IO to fill out the request | |
let req' = Auth.signRequest account req | |
join $ P.lift $ HTTP.withHTTP req' manager $ \resp -> | |
return (P.for (HTTP.responseBody resp) P.yield) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Azure.Storage.Protocol.HttpHelpers | |
( httpRequest | |
) where | |
import Control.Monad (unless) | |
import qualified Data.ByteString as BS | |
import Network.HTTP.Client | |
import Pipes | |
import Pipes.Safe | |
httpRequest :: (MonadSafe m, MonadIO m) => Request -> Manager -> Producer BS.ByteString m () | |
httpRequest r m = | |
bracket | |
(liftIO $ responseOpen r m) | |
(liftIO . responseClose) | |
(produce . responseBody) | |
where | |
produce body = loop | |
where | |
loop = do | |
chunk <- lift $ liftIO $ brRead body | |
unless (BS.null chunk) $ | |
yield chunk >> loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listContainers :: (MonadSafe m, MonadIO m) => HTTP.Manager -> AccountName -> Producer ContainerName m () | |
listContainers manager account = do | |
req <- lift $ liftIO $ fillOutTemplate template | |
let signedReq = Auth.signRequest account req | |
sax (httpRequest signedReq manager) >-> elementContent "Name" >-> P.map ContainerName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment