-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Using fetch for unix socket #8821
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
Unstale. |
Browser fetch does not support sockets. Node fetch declined it because of the lack of browser support. I would be opposed to it too. Otherwise socket support was added in #4176. So, respectfully, declined. |
Thank you:) |
BackgroundA unix socket is really just an alternative underlying transport for the request. It could be considered a proxy for the request. For background, here is how other languages / frameworks implement this: In Node you can specify a In Go you can specify a custom It seems that in Python you have to use this package: https://pypi.org/project/requests-unixsocket/. You use the regular request method, but you specify your url to fetch as something like this ProposalI propose we add this as a non standard extension in the unstable
interface CreateHttpClientOptions {
/** A certificate authority to use when validating TLS certificates. Certificate data must be PEM encoded.
*/
caData?: string;
+
+ /** A proxy to use for the requests made with this socket. */
+ proxy?: Deno.UnixConnectOptions;
}
In the future this could be extended to also allow allow An example: const client = Deno.createHttpClient({
proxy: {
transport: "unix",
path: "/var/run/docker.sock"
}
});
const res = await fetch("http://localhost/info", { client }); By treating the unix socket as a proxy we can avoid issues related to things like needing to specify a custom The security considerations for this would be the same as |
Hi, I'm also looking for HTTP over Unix. I find the above usage of 'proxy' interesting because the term is already defined for http interactions; case in point, |
I've published a workaround as import { fetchUsing, UnixDialer } from "https://deno.land/x/[email protected]/mod.ts";
const dialer = new UnixDialer("/var/run/docker.sock");
const resp = await fetchUsing(dialer, "http://localhost/v1.24/images/json"); To run that example locally:
This module is very limited (no POST, no socket reuse, etc) but should work fine for some basic use-cases. |
Any news? Cannot use some npm library which use unix socket fetch, like Related #17910 |
Workaround import { fetch, Agent } from 'undici'
const resp = await fetch('http://localhost/version', {
dispatcher: new Agent({
connect: {
socketPath: '/var/run/docker.sock'
}
})
})
console.log(await resp.text()) $ deno run --unstable -A ./reproduce.mjs
{"Platform":... |
Any news?
|
@loynoir use |
@lucacasonato Instead of changing Deno's definition of fetch (and RequestInit etc) to take a new const client = Deno.createHttpClient({
proxy: {
transport: "unix",
path: "/var/run/docker.sock"
}
});
const res = await client.fetch("http://localhost/info"); This possibility would also make so any Deno API compatibility layers re-implementing (This idea occurred to me when I saw a similar pattern in Cloudflare Workers' classic HTTP Service Bindings, where you make a request to (or through) a Cloudflare Worker by calling the fetch method on the worker object as if it was the global fetch function.) |
Is it possible to use
fetch
for unix socket (e.g. to call docker API)? If not, what is the best way to communicate via HTTP through unix socket?The text was updated successfully, but these errors were encountered: