在Haskell中连接本地套接字的最佳方法是什么?
连接完成后,HTTP用于通信(我想连接到本地Docker套接字)
wreq和http-client似乎只处理URL而不是套接字。
在命令行上我可以使用curl --unix-socket /var/run/docker.sock http:/containers/json
但是我在hackage的curl包中找不到等效的--unix-socket
。
答案 0 :(得分:2)
我认为可以使用http-client。您应create Manager
与custom hook建立联系。
答案 1 :(得分: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