I can't figure out how to get the Content-Length header from the response from a server:
import Network.HTTP.Conduit
main = do
headers <- getHeaders "http://fdsfdsfds.fd"
--??? this doesn't compile and a wrong way to go
head $ filter (\x -> hContentLength (fst x)) headers
getHeaders :: String -> IO ResponseHeaders
getHeaders url = do
req <- parseUrl url
res <- withManager $ httpLbs req
return $ responseHeaders res
Your suggestions?
That's because hContentLength
is just a case-insensitive string, not a function. You can't apply it.
However, since CI a
is an instance of Eq
for any Eq a
, you can simply use lookup
:
getContentLength :: ResponseHeaders -> Maybe ByteString
getContentLength = lookup hContentLength