Skip to content

Instantly share code, notes, and snippets.

@ocharles
Created June 20, 2012 09:56
Using http-conduit to merely print the response is cumbersome.
{-# LANGUAGE OverloadedStrings #-}
import Data.CaseInsensitive (original)
import Data.Conduit (($$), yield)
import Data.Conduit.Binary (sinkHandle)
import Network.HTTP.Conduit
import Network.HTTP.Types
import System.IO (stdout)
import qualified Data.ByteString.Char8 as S
main :: IO ()
main = do
req <- parseUrl "http://google.com/"
withManager $ \m -> do
res <- http req m
(do yieldLn $ showStatus res
yieldLn $ showHeaders res
responseBody res) $$ sinkHandle stdout
where yieldLn x = yield x >> yield "\n"
showStatus :: Response b -> S.ByteString
showStatus res = S.unwords [ S.pack . show . responseVersion $ res
, S.pack . show . statusCode $ responseStatus res
, statusMessage $ responseStatus res ]
showHeaders :: Response b -> S.ByteString
showHeaders = S.intercalate "\n" . map showHeader . responseHeaders
where showHeader (k,v) = S.intercalate ": " [original k, v]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment