HTTPUnixSocketConnection
Really small Python class that extends native http.client.HTTPConnection allowing sending HTTP requests to Unix Sockets
Installation
Poetry
poetry add httpunixsocketconnection
pip
pip install httpunixsocketconnection
Usage
Because the class base is http.client.HTTPConnection
, the API is almost the same.
Only the constructor and connect
method is different.
With the rest please follow the official docs.
from httpunixsocketconnection import HTTPUnixSocketConnection
conn = HTTPUnixSocketConnection(
unix_socket="/var/run/some.unix.socket"
)
Example: Getting list of Docker Containers
from httpunixsocketconnection import HTTPUnixSocketConnection
conn = HTTPUnixSocketConnection("/var/run/docker.sock")
conn.request("GET", "/containers/json")
res = conn.getresponse()
print(res.status, res.reason)
content = res.read().decode("utf-8")
print(content)