Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Libs by

I want to a HTTP request over a UNIX socket, like the following example using curl and docker:

$ curl --unix-socket /var/run/docker.sock http://localhost/images/json
    "Containers": -1,
    "Created": 1577395270,
    "Id": "sha256:ce6c1e7ac56533e2742030f033cf0d8cf0adc996c7bb87453eb5adc266b2ef2e",
    "Labels": null,
    "ParentId": "",
    "RepoDigests": [
    "RepoTags": [
    "SharedSize": -1,
    "Size": 1461385,
    "VirtualSize": 1461385

As far as I've seen, clj-http doesn't seem to support this.

What would be a recommended/idiomatic way of doing this in Clojure?

1 Answer

+1 vote

The short answer is: you cant.

Java doesn't have support (as far as I can find/see) for writing to unix sockets.

The longer answer is:

You can send and pipe to sockets. The netcat "nc" tools can work here i.e you can open a tcp socket with:

Option A
Use netcat

nc -lk localhost 8787

And then find a way to nc to redirect to the socket you want

Option B.

You could call curl as above using an external process with ProcessBuilder.

Option C.

There are libraries that allow you to create unix sockets from java, like https://github.com/mcfunley/juds. This involves using jni which the "juds" abstracts away