Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active August 29, 2015 14:26
Show Gist options
  • Save Porges/153837bd72ccc739da8b to your computer and use it in GitHub Desktop.
Save Porges/153837bd72ccc739da8b to your computer and use it in GitHub Desktop.
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)
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
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