2016-02-17 80 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 
相關問題