HTTP.UnixSocket (http_fetch v0.8.0)
Unix Domain Socket support for HTTP requests.
This module provides HTTP communication over Unix Domain Sockets (UDS), commonly used for local inter-process communication with services like Docker daemon, systemd, and other local services.
Usage
# Connect to Docker daemon
HTTP.fetch("http://localhost/version", unix_socket: "/var/run/docker.sock")
# Connect to any Unix socket service
HTTP.fetch("http://localhost/status", unix_socket: "/tmp/my-service.sock")Implementation Notes
- Uses
:gen_tcpwith{:local, path}for Unix socket connections - Manually constructs HTTP/1.1 requests
- Parses HTTP responses to create
HTTP.Responsestructs - Supports all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD)
- Handles chunked transfer encoding
- Compatible with existing
HTTP.ResponseAPI (json/1, text/1, etc.)
Limitations
- Does not support streaming responses (buffers entire response)
- Does not support HTTPS over Unix sockets (not applicable)
- Request/response timeout is fixed at 30 seconds
Summary
Functions
Executes an HTTP request over a Unix Domain Socket.
Functions
@spec request(String.t(), HTTP.Request.t(), integer()) :: {:ok, HTTP.Response.t()} | {:error, term()}
Executes an HTTP request over a Unix Domain Socket.
Parameters
socket_path- Path to the Unix socket filerequest-HTTP.Requeststruct with method, url, headers, and bodytimeout- Optional timeout in milliseconds (default: 30000)
Returns
{:ok, %HTTP.Response{}}on success{:error, reason}on failure