HTTP over AF_UNIX: HTTP connection to unix socket

时光总嘲笑我的痴心妄想 提交于 2019-12-21 03:20:09

问题


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

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?

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.

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

Many Thanks in advance.


回答1:


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.

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.

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 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



来源:https://stackoverflow.com/questions/14771172/http-over-af-unix-http-connection-to-unix-socket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!