ureq
ureq copied to clipboard
unix domain socket support?
Don't find in the docs about unix domain socket support. Can provider an example for this?
Does ureq support unix domain sockets?
Not currently, no.
With ureq
's focus on simplicity, do you think there'd be interest in accepting a PR to add unix domain socket support?
What would the API look like?
Some initial ideas:
Add a transport type to the agent:
let agent = ureq::AgentBuilder::new()
.transport(ureq::TransportType::UnixSocket("/var/snap/lxd/common/lxd-user/unix.socket"))
.build();
// This is sent over the socket.
let resp = agent.get("http://lxd/1.0/instances").call()?;
Allow setting a raw transport stream (eg. maybe anything that implements Read and Write) to read and write from in the agent:
let agent = ureq::AgentBuilder::new()
.transport(std::os::unix::net::UnixStream::connect("/var/snap/lxd/common/lxd-user/unix.socket"))
.build();
// This is sent over the socket.
let resp = agent.get("http://lxd/1.0/instances").call()?;
Embed the socket in the protocol string somehow (note: there is no standard for this yet - see https://github.com/whatwg/url/issues/577 ):
ureq::get("unix:/var/snap/lxd/common/lxd-user/unix.socket:http://lxd/1.0/instances").call()?;
Adding to the mix of ideas, allow for ureq::get(path
s in the form:
http+unix://%2Ftmp%2Fapi.sock/service?query=1
-
scheme
:http+unix://
, this allows https to still be conveniently expressed -
authority
:%2Ftmp%2Fapi.sock
, sock path, requires the path to be URL encoded -
path
:/service?query=1
ureq
would make configuring the underlying transport transparent to the caller here: https://github.com/algesten/ureq/blob/main/src/unit.rs#L369-L375