-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to use a unix socket? #39
Comments
There isn't a way yet, but it definitely makes sense to provide when What makes sense for the best way to provide this? Just adding to the connector to look for the |
The |
The url crate seems to support the let url = Url::parse("unix:/run/foo.socket").unwrap(); Would it be possible to include the path with something like this? let url = Url::parse("unix:/var/run/docker.sock/containers/json").unwrap(); I'm also wondering if According to the Docker Remote API page, older curl version used |
So looking around, I see two possible routes.
|
@seanmonstar in case you were looking for feedback, I definitely prefer the first option because it allows to leave the scheme and host-fqdn part untouched. This is important if at the other end of the unix-socket there is a virtualhost-aware server, or something doing TLS-ALPN (or similar upper protocol detection/negotiation). |
I've wanted "use a socket for HTTP requests" for a while because setting up a proxy on a port doesn't lock it down to just the current user. Not that that project is ever going to use Rust at its network level anytime soon, but it's not an unheard of use case. |
I think I prefer this being |
Any progress in this area? |
Doing some research in how it is done elsewhere:
|
I saw a implementation of unix socket in boondock using hyper 0.9.0 https://github.com/faradayio/boondock/blob/master/src/unix.rs |
This also might not be a non-Windows thing in the future as well: https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/ |
I came across the |
Is there any workaround now? I was looking at something with the |
Has there been any progress on this? I am also looking for a way to use the Docker authorization via the Docker socket, but without going through the loopback address. |
@seanmonstar .. I've designed a solution to support Unix Socket... and we already use it in our codebase. I can make it more generic and reqwesty .. and then submit a PR, in case if you're not already working on it. Please let me know your thoughts. |
@seanmonstar To be precise, I think you mean something like |
It would be nice if this could work on Windows too via named pipes. |
I found this discussion after trying to use I kind of wish that |
I would also use this if it was available. I'm making a REST API, but I need to be able to access it by mounting a Unix socket into a container. Reqwest seems pretty de-facto for making HTTP requests so it would be really nice to be able to use it for Unix sockets too. |
I'll also note that Docker's socket talks HTTP. |
What's the current status of this? As @snawaz mentioned it's already partially ready. Would love some updates as I'd love to talk to docker over a unix socket. Cheers :) |
This is really easy to do with Hyper. Any chance of exposing the necessary methods? Or better yet, creating a Request Client from a Hyper Client? |
I'm not seeing anything obvious in the docs. Do you have a link to the methods involved (or example code)? |
* fix: Corrently infer in_app for impl functions * fix: Move function_starts_with to backtrace_support
if you were talking to me, you could take a look at my pull request on hyperlocal for some code examples |
I would recommend the unix: scheme as well because it means that all reqwest users would get it automatically (or with a feature enabled). It would also mean that all tools that use reqwest would have a consistent syntax for specifying UNIX sockets. |
Hi everyone. Any update on this issue? Since it has been opened for 4 years I wonder if there is anything to do to help :) |
This would be a great addition! |
Apache's ProxyPass uses the syntax |
It seems like there's an open PR that would solve this. Any change to have this merged in? |
It would be really nice to see this PR merged. |
For anyone running into this, I've found that the hyper-socket crate requires very few changes to work with the latest hyper/ tokio. https://docs.rs/hyper-socket/latest/hyper_socket/ Doesn't solve the issue for |
Would be really great to have 🙏 |
Would be nice to have. I agree with @asf-stripe that instead of file name, we can provide callback that creates socket, it can be even linux File descriptor. And on top of it create helper method that accepts file name as String. Theoretically it can even be some kind of rust stream instead of raw FD, but I don't know inner workings of library to judge. If out can be some stream, then even TLS part can be build on top of this. |
Here is the format used by nginx, which i think is better than anything |
So, can i use reqwest with Unix sockets? |
I was struggeling with getting this to work as well. use axum::{
body::Body,
http::{Method, Request, StatusCode}
};
use http_body_util::BodyExt;
use hyper_util::rt::TokioIo;
use std::path::PathBuf;
use tokio::net::UnixStream;
pub async fn client(container_name: String) {
let path = PathBuf::from("/run/user/1000/podman/podman.sock");
let stream = TokioIo::new(UnixStream::connect(path).await.unwrap());
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await.unwrap();
tokio::task::spawn(async move {
if let Err(err) = conn.await {
println!("Connection failed: {:?}", err);
}
});
let request = Request::builder()
.method(Method::GET)
.uri("/v4.0.0/libpod/containers/lldap/logs?stdout=true")
.header("Host", "d")
.body(Body::empty())
.unwrap();
let response = sender.send_request(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = response.collect().await.unwrap().to_bytes();
let body = String::from_utf8(body.to_vec()).unwrap();
println!("{}", body);
}
#[tokio::main]
async fn main() {
client("lldap".to_string()).await;
} |
This is a small example using just hyper (no need for axum), to make requests to a local unix domain socket: https://github.com/cablehead/stacks/blob/main/src-tauri/src/cli.rs#L30 Dropping back to raw hyper though, you lose, http1.1 / http2 negotiation, ssl, and connection pooling. Although 🤔 .. those things are generally less necessary for the use cases where you'd find yourself wanting a local socket.. |
there have been several solutions posted for solving this in different ways using |
Is there any update on this? |
This comment has been minimized.
This comment has been minimized.
Preferrably, we get a Connection impl for UnixStream into hyper_util to avoid the new UnixStreamWrapper. Closes seanmonstar#39
Preferrably, we get a Connection impl for UnixStream into hyper_util to avoid the new UnixStreamWrapper. Closes seanmonstar#39
Preferrably, we get a Connection impl for UnixStream into hyper_util to avoid the new UnixStreamWrapper. Closes seanmonstar#39
How much work would be necessary to make reqwest fully generic over any type implementing |
Any updates on this topic? |
We'd also be interested in using reqwest with a custom |
This is the oldest issue in this repository (8 years old) and it's a shame it's still open. So many people are showing their support and we're still waiting for an answer. The last comment from the maintainer was 7 years ago! A "yes we're working on it" or "no it won't be implemented" is enough. |
What I'd like to see: being able to run reqwest over an arbitrary |
I would like to do the equivalent of:
There's the unix_socket crate but I'm not sure if I can use it with reqwest.
The text was updated successfully, but these errors were encountered: