2016-02-17 37 views
2

连接到Haskell中的本地套接字的最佳方式是什么?连接到Haskell中的本地HTTP套接字

一旦连接建立HTTP用于通信,(我想连接到本地多克尔插座)

WREQ和HTTP客户端似乎只与网址,而不必插座处理。

在命令行上,我可以使用curl --unix-socket /var/run/docker.sock http:/containers/json,但我无法在hackage上的curl包中找到等价的--unix-socket

+0

我想你说的是Berkeley套接字。通过websockets包可以获得该https://github.com/jaspervdj/websockets/blob/master/example/client.hs的示例客户端。 – Sibi

回答

0

另一个,也许更原始的一种选择是使用第二传输,还有一个功能HTTP/1.1 request-maker内:

... 
import Data.Conduit 
import SecondTransfer.Http1.Proxy (ioProxyToConnection) 
import SecondTransfer.Http1.Types 
import Control.Lens 

main = 
    do 
    ... 
    -- Somehow get a socket from the networking package, i.e, with type 
    -- Network.Socket.Socket . AF_UNIX sockets are OK, and then wrap it 
    -- in a set of I/O callbacks: 
    io_callbacks <- handshake =<< socketIOCallbacks my_socket 

    -- Puts and receives the data for the http request, get the results. Only needs the 
    -- headers that will be sent over the tube, and the streaming contents 
    -- with request data. 
    let 
     request :: HttpResponse IO 
     request = HttpRequest [("host", 
           "http://127.0.0.1:8080"), 
          ...] 
          (yield "") 

    -- Perform the request, get the response. 
    response <- ioProxyToConnection io_callbacks request 

    -- Use the lens interface to access the headers: 
    putStrLn . show $ response ^. headers_Rp 

    -- You can consume a streaming response using response ^. body_Rp 
相关问题