ureq icon indicating copy to clipboard operation
ureq copied to clipboard

unix domain socket support?

Open futurist opened this issue 2 years ago • 6 comments

Don't find in the docs about unix domain socket support. Can provider an example for this?

futurist avatar Aug 31 '22 02:08 futurist

Does ureq support unix domain sockets?

samuelallan72 avatar Oct 05 '23 23:10 samuelallan72

Not currently, no.

jsha avatar Oct 06 '23 00:10 jsha

With ureq's focus on simplicity, do you think there'd be interest in accepting a PR to add unix domain socket support?

cablehead avatar Feb 27 '24 16:02 cablehead

What would the API look like?

algesten avatar Mar 11 '24 16:03 algesten

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()?;

samuelallan72 avatar Mar 11 '24 22:03 samuelallan72

Adding to the mix of ideas, allow for ureq::get(paths 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

cablehead avatar Mar 12 '24 01:03 cablehead