FWIW: http-client を使用してその UNIX ソケットを使用する場合:
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client
import Network.HTTP.Client.Internal (Connection, openSocketConnection, makeConnection)
import Network.Socket.ByteString (sendAll, recv)
import qualified Control.Exception as E
import qualified Network.Socket as NS
main :: IO ()
main = do
mgr <- newManager defaultManagerSettings {
managerRawConnection = createUnixConnection
}
-- This changes in http-client-0.5, use parseUrlThrow
req <- parseUrl "http://localhost/whatever"
res <- httpLbs req mgr
print (responseBody res)
createUnixConnection :: IO (Maybe NS.HostAddress -> String -> Int -> IO Connection)
createUnixConnection = return $ \_ _ _ -> openUnixConnection "warp.sock"
openUnixConnection :: String -> IO Connection
openUnixConnection addr = E.bracketOnError
(NS.socket NS.AF_UNIX NS.Stream NS.defaultProtocol)
(NS.close)
$ \sock -> do
NS.connect sock sockAddr
socketConnection sock chunksize
where
sockAddr = NS.SockAddrUnix addr
chunksize = 8192
-------------------------------------------------------------------------------
-- Copied from http-client
-------------------------------------------------------------------------------
socketConnection :: NS.Socket -> Int -> IO Connection
socketConnection socket chunksize = makeConnection
(recv socket chunksize)
(sendAll socket)
(NS.close socket)