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_tcp with {:local, path} for Unix socket connections
  • Manually constructs HTTP/1.1 requests
  • Parses HTTP responses to create HTTP.Response structs
  • Supports all standard HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD)
  • Handles chunked transfer encoding
  • Compatible with existing HTTP.Response API (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

request(socket_path, request, timeout \\ 30000)

@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 file
  • request - HTTP.Request struct with method, url, headers, and body
  • timeout - Optional timeout in milliseconds (default: 30000)

Returns

  • {:ok, %HTTP.Response{}} on success
  • {:error, reason} on failure