-
Notifications
You must be signed in to change notification settings - Fork 120
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
Support unix sockets #139
Comments
Hi and thanks for the issue! I agree that Finch should support this. I have not looked in to this very much yet, but rather than using a scheme like |
Hi @sneako , thanks for your quick reply! Personally I don't have a strong opinion about which approach to use, but I'm afraid that using the Anyway, once the preferred approach is defined I would be happy to try and implement it, if that's OK for you :) |
Hi @dallagi, sorry for the delay in getting back to you. I have been thinking about this a bit in the meantime, and have come to the conclusion that my initial proposal of using the local_address type would probably not be sufficient. I have not personally used TLS over a unix socket, however based on my limited research it does seem to be entirely possible. There is no way to specify that you would like to use TLS in the local_address tuple that I had proposed, therefore your proposal of |
This PR was brought to my attention that highlights some potential issues that the current proposal may introduce benoitc/hackney#653 |
Hi @sneako, Thanks for the heads up about the potential issues! However, personally I can’t think of a better alternative. |
out of curiosity, what would be an actual example call to |
Hi @wojtekmach you are absolutely right, I’ll try to come up with some practical examples. Let’s say we want to hit the _ping api exposed by a local docker daemon listening on Using an approach similar to hackney’s it would look like this: Finch.build(:get, "http+unix://%2Fvar%2Frun%2Fdocker.sock/v1.41/_ping") Otherwise, another option could be to go with a tuple, which for example could look like this: Finch.build(:get, {"http", "/var/run/docker.sock", "/v1.41/_ping"}) Headers and body would keep working same way as now. To be clear I don't have a strong preference, as IMHO none of them is inherently better than the other, and of course there may also be some better option I didn't consider. |
I thinked a bit more about this. If I had to pick one to these two approaches myself I’d probably go with the former, ie. hackney’s approach. However, the simplest approach may actually be to skip the This may look something like this: %Finch.Request{scheme: :"http+unix", host: "/var/run/docker.sock", port: 0, method: "GET", path: "/v1.41/_ping", headers: [], body: nil, query: nil} Overall, in my opinion this last approach could be a good way to start, as it would allow Finch to add support for unix sockets without changing its user-facing API, while still keeping the possibility to update the |
In curl, setting the unix socket is just another option instead of messing with the url: $ curl --unix-socket /var/run/docker.sock http://localhost/v1.41/_ping
OK (setting the url to I think this is relevant here. Here's an idea how we could support this in Finch: {:ok, _} =
Finch.start_link(
name: MyFinch,
pools: %{
{:local, "/var/run/docker.sock"} => [size: 10]
}
)
Finch.build(:get, "http://localhost/v1.41/_ping", unix_socket: "/var/run/docker.sock")
|> Finch.request() Note, in our pool map we use the path to the socket, not the host. I believe the host is mostly or totally irrelevant. For example, It is ignored by the docker server:
Btw, given at least for Docker, the host is irrelevant, we can also use empty host like this: iex> URI.parse("http:///v1.41/_ping") |> Map.take([:host, :path, :scheme])
%{host: "", path: "/v1.41/_ping", scheme: "http"}
iex> :uri_string.parse("http:///v1.41/_ping")
%{host: "", path: "/v1.41/_ping", scheme: "http"} WDYT? |
I like @wojtekmach's proposal of using a new |
I have a similar use case that requires communicating with a UNIX socket. |
Yes, let's go with the approach Wojtek proposed. Thanks @cgerling! |
Hello,
Mint natively supports making requests on unix sockets by setting the address to
{:local, "/path/to/socket.sock"}
and the port number to0
, for example:For more context, tests for this functionality in Mint can be found here.
However, to my knowledge Finch does not currently allow this.
In case this feature may be desirable, a possible approach could be to do as Hackney does, ie. supporting url schemas in the form of eg.
"http+unix"
.The text was updated successfully, but these errors were encountered: