I can't create a custom header without using OverloadedStrings
import Data.Aeson
import qualified Data.ByteString.Lazy as B
import Network.HTTP.Conduit
import qualified Network.HTTP.Headers as HHeaders
import qualified Network.HTTP.Types as HTypes
import qualified Data.ByteString.Char8 as C8
import qualified Data.ByteString.Lazy.Char8 as LC8
-- myHeader1 = (HHeaders.HdrAccept $ C8.pack "some data")
myHeader1 = HHeaders.mkHeader HHeaders.HdrAccept "some data"
get :: String -> IO (Response LC8.ByteString)
get url1 = do
req1 <- parseUrl url1
res1 <- withManager $ httpLbs req1 { method = HTypes.methodGet, requestHeaders = [myHeader1] }
return res1
An error:
Couldn't match type ‘HHeaders.Header’
with ‘(HTypes.HeaderName, C8.ByteString)’
Expected type: HTypes.Header
Actual type: HHeaders.Header
In the expression: myHeader1
In the ‘requestHeaders’ field of a record
What am I doing wrong?
Network.HTTP.Conduit and Network.HTTP.Headers are from incompatible HTTP libraries. Request headers for
http-conduit/http-clientcan be created using thehttp-typeslibrary:To clarify:
You were importing Network.HTTP.Headers from the
HTTPlibrary. Although the imports look similar, this is a self-contained library which defines it's own header types and not intended to be used with http-types.http-clientis compatible with thehttp-types. If you follow the definition for RequestHeader it will lead you tohttp-types.In the future, one way to check the compatibility of orthogonal libraries is to look at the build depends on the Hackage index or follow the types as far as possible.