在Haskell中连接到本地套接字的最佳方式是什么?
建立连接后,将使用HTTP进行通信(我希望连接到本地Docker套接字)
wreq和http-client似乎只处理URL,而不处理套接字。
在命令行上,我可以使用curl --unix-socket /var/run/docker.sock http:/containers/json,但在hackage上的curl包中找不到与--unix-socket等效的命令。
发布于 2016-02-17 19:37:50
我认为使用http-client是可能的。您应该使用create Manager和custom hook建立连接。
发布于 2016-02-17 21:42:27
另一种可能更原始的选择是使用第二次传输,里面有一个函数式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_Rphttps://stackoverflow.com/questions/35455468
复制相似问题