Created
June 20, 2012 09:56
Using http-conduit to merely print the response is cumbersome.
This file contains hidden or 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
{-# 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