created_at2023-01-23 00:03:05.023663
updated_at2023-01-23 01:41:32.512666
descriptionHyper bindings for Unix domain sockets
Chris Cowan (Macil)



🔌 ✨


Hyper client and server bindings for Unix domain sockets, with Windows support

Hyper is a rock solid Rust HTTP client and server toolkit. Unix domain sockets provide a mechanism for host-local interprocess communication. hyperlocal-with-windows builds on and complements Hyper's interfaces for building Unix domain socket HTTP clients and servers.

This is useful for exposing simple HTTP interfaces for your Unix daemons in cases where you want to limit access to the current host, in which case, opening and exposing tcp ports is not needed. Examples of Unix daemons that provide this kind of host local interface include Docker, a process container manager.

This library is a fork of hyperlocal with Windows support added. This project is not Windows-specific; it is cross-platform. The Windows support has a limitation: when acting as a server and listening on a Unix socket, the underlying socket may remain open until the program exits even if the server is shut down. This is not expected to be a problem for usual programs that listen on a Unix socket until the program exits, but this may be a problem for other use cases. This library will be discontinued once Windows support is added upstream into hyperlocal.


Add the following to your Cargo.toml file

hyperlocal-with-windows = "0.8"



A typical server can be built with hyperlocal_with_windows::server::UnixServerExt.

use std::{error::Error, fs, path::Path};
use hyper::{
    service::{make_service_fn, service_fn},
    Body, Response, Server,
use hyperlocal_with_windows::{remove_unix_socket_if_present, UnixServerExt};

const PHRASE: &str = "It's a Unix system. I know this.";

async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let path = Path::new("/tmp/hyperlocal.sock");


    let make_service = make_service_fn(|_| async {
        Ok::<_, hyper::Error>(service_fn(|_req| async {
            Ok::<_, hyper::Error>(Response::new(Body::from(PHRASE)))



To test that your server is working you can use an out of the box tool like curl

$ curl --unix-socket /tmp/hyperlocal.sock localhost

It's a Unix system. I know this.


hyperlocal-with-windows also provides bindings for writing unix domain socket based HTTP clients using Hyper's native Client interface.

Configure your Hyper client using hyper::Client::builder().

Hyper's client interface makes it easy to send typical HTTP methods like GET, POST, DELETE with factory methods, get, post, delete, etc. These require an argument that can be tranformed into a hyper::Uri.

Since Unix domain sockets aren't represented with hostnames that resolve to ip addresses coupled with network ports, your standard over the counter URL string won't do. Instead, use a hyperlocal_with_windows::Uri, which represents both file path to the domain socket and the resource URI path and query string.

use std::error::Error;
use hyper::{body::HttpBody, Client};
use hyperlocal_with_windows::{UnixClientExt, Uri};
use tokio::io::{self, AsyncWriteExt as _};

async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let url = Uri::new("/tmp/hyperlocal.sock", "/").into();

    let client = Client::unix();

    let mut response = client.get(url).await?;

    while let Some(next) = response.data().await {
        let chunk = next?;


Doug Tangren (softprops) 2015-2020

Commit count: 172

cargo fmt