首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接到Haskell中的本地HTTP套接字

连接到Haskell中的本地HTTP套接字
EN

Stack Overflow用户
提问于 2016-02-17 19:29:38
回答 2查看 294关注 0票数 2

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

建立连接后,将使用HTTP进行通信(我希望连接到本地Docker套接字)

wreq和http-client似乎只处理URL,而不处理套接字。

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

EN

回答 2

Stack Overflow用户

发布于 2016-02-17 19:37:50

我认为使用http-client是可能的。您应该使用create Managercustom hook建立连接。

票数 2
EN

Stack Overflow用户

发布于 2016-02-17 21:42:27

另一种可能更原始的选择是使用第二次传输,里面有一个函数式HTTP/1.1 request-maker

代码语言:javascript
复制
...
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35455468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档