通过AF_UNIX的HTTP:与unix套接字的HTTP连接 [英] HTTP over AF_UNIX: HTTP connection to unix socket

查看:195
本文介绍了通过AF_UNIX的HTTP:与unix套接字的HTTP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有HTTP服务器,对于它,我们有基于HTTP客户端的应用程序(在Linux上)可以正常工作。

We have HTTP server , for which we have HTTP client based application (on Linux) working fine.

但是现在我们需要从客户端应用程序监听Unix域套接字。
那么是否可以从unix域套接字发送/接收httprequest和httpresponse数据包?

But now we need to listen on Unix domain sockets from our client application. So is it possible to send/receive httprequest, httpresponse packet from the unix domain socket?

场景1:连接到本地主机时,需要消除通过将HTTP连接到unix套接字而不是HTTPS连接到
本地端口来减少SSL
的开销。

Scenerio1:When connecting to localhost, it is required to eliminate the SSL overhead by connecting HTTP to the unix socket instead of HTTPS to the local port.

基本上在寻找一种标准的编码unix套接字路径的标准

Basically Looking for a standard encoding a unix socket path in an HTTP URL.

非常感谢。

推荐答案

只要您的套接字是流套接字( SOCK_STREAM 而不是 SOCK_DGRAM ),在技术上就可以实现。 HTTP中没有需要TCP / IP的东西,只需要一个可靠的双向流。

So long as your socket is a stream socket (SOCK_STREAM rather than SOCK_DGRAM) then it's technically possible. There's nothing in HTTP that requires TCP/IP, it just requires a reliable bidirectional stream.

但是我从未见过HTTP客户端知道如何连接到这样的插座。据我所知,没有URL格式可以正常工作,如果您实际上需要使用URL与服务器进行通讯。

However I've never seen an HTTP client that knows how to connect to such a socket. There's no URL format that I know of that would work, should you actually need to use a URL to talk to the server.

还请注意,普通Web服务器中的某些内容当您不使用TCP / IP时,依赖(例如 getpeername()来识别客户端)毫无意义。

Also note that some things that normal web servers depend on (such as getpeername(), to identify the client) make no sense when you're not using TCP/IP.

EDIT 我刚刚看到了您有关将 localhost 映射到UNIX套接字的编辑。这是完全可行的,您只需要确保客户端知道如何找到应该使用的UNIX套接字的路径即可,而不是连接到127.0.0.1:xxx

EDIT I just saw your edit about mapping localhost to the UNIX socket. This is perfectly feasible, you just need to ensure that the client knows how to find the path of the UNIX socket that should be used instead of connecting to 127.0.0.1:xxx

这篇关于通过AF_UNIX的HTTP:与unix套接字的HTTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆