#hyper #unix #sockets #http


Hyper bindings for unix domain sockets

7 releases (breaking)

0.6.0 Sep 23, 2018
0.5.0 Aug 12, 2018
0.4.1 Oct 8, 2017
0.4.0 Aug 14, 2017
0.1.0 Jan 3, 2016

#6 in #unix

Download history 231/week @ 2018-12-20 47/week @ 2018-12-27 810/week @ 2019-01-03 500/week @ 2019-01-10 521/week @ 2019-01-17 769/week @ 2019-01-24 906/week @ 2019-01-31 505/week @ 2019-02-07 562/week @ 2019-02-14 708/week @ 2019-02-21 1060/week @ 2019-02-28 755/week @ 2019-03-07 440/week @ 2019-03-14 755/week @ 2019-03-21 798/week @ 2019-03-28

2,112 downloads per month
Used in 7 crates (4 directly)

MIT license

345 lines

hyperlocal Build Status Coverage Status crates.io docs.rs Master API docs

hyper client and server bindings for unix domain sockets

Hyper is a rock solid rustlang HTTP client and server tool kit. Unix domain sockets provide a mechanism for host-local interprocess communication. Hyperlocal 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.


Add the following to your Cargo.toml file

hyperlocal = "0.5"



A typical server can be built with hyperlocal::server::Server

extern crate hyper;
extern crate hyperlocal;
extern crate futures;

use std::fs;
use std::io;

use hyper::{header, Body, Request, Response};
use hyper::service::service_fn;

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

fn hello(_: Request<Body>) -> impl futures::Future<Item = Response<Body>, Error = io::Error> + Send {
            .header(header::CONTENT_TYPE, "text/plain")
            .header(header::CONTENT_LENGTH, PHRASE.len() as u64)
            .expect("failed to create response")

fn run() -> io::Result<()> {
    let path = "test.sock";
    if let Err(err) = fs::remove_file("test.sock") {
        if err.kind() != io::ErrorKind::NotFound {
            return Err(err);
    let svr = hyperlocal::server::Server::new().bind(path, || service_fn(hello))?;
    println!("Listening on unix://{path} with 1 thread.", path = path);

fn main() {
    if let Err(err) = run() {
        eprintln!("error starting server: {}", err)


You can communicate over HTTP with Unix domain socket servers using hyper's Client interface. Configure your hyper client using Client::configure(...).

Hyper's client interface makes it easy to issue typical HTTP methods like GET, POST, DELETE with factory methods, get, post, delete, ect. 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 ports, your standard url string won't do. Instead, use a hyperlocal::Uri which represents both file path to the domain socket and the resource uri path and query string.

extern crate futures;
extern crate hyper;
extern crate hyperlocal;
extern crate tokio_core;

use std::io::{self, Write};

use futures::Stream;
use futures::Future;
use hyper::{Client, rt};
use hyperlocal::{Uri, UnixConnector};

fn main() {
    let client = Client::builder()
        .keep_alive(false) // without this the connection will remain open
        .build::<_, ::hyper::Body>(UnixConnector::new());
    let url = Uri::new("test.sock", "/").into();

    let work = client
        .and_then(|res| {
            println!("Response: {}", res.status());
            println!("Headers: {:#?}", res.headers());

            res.into_body().for_each(|chunk| {
                    .map_err(|e| panic!("example expects stdout is open, error={}", e))
        .map(|_| {
        .map_err(|err| {
            eprintln!("Error {}", err);


Doug Tangren (softprops) 2015-2018


~98K SLoC