Description
I previously opened #15159 asking about exposing Unix Socket functionality in the CurlHandler, and @stephentoub closed the issue with an excellent explanation.
However, as things in .NET Core Land have progressed, I'm wondering again about this.
Basically, the dotnet/corert project is looking to enable native compilation, which means that C# can potentially be used to create useful, native cross-platform tools, much like Go.
It's very common for these command-line applications or services on Linux to need to communicate over Unix Sockets; for example, /var/run/docker.sock
is used to talk to the local Docker daemon.
I had a quick look at the HttpClient
and HttpRequestMessage
APIs, and the internal handling of HttpRequestMessage
by CurlHandler
.
There is a potential opportunity to introduce this functionality in an obscure but workable way without breaking or even changing the public API, by using the Properties
dictionary on HttpRequestMessage
(which is a Dictionary<string, object>
). One could set a property in here, perhaps like:
var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/list");
message.Properties["Curl.UnixSocketPath"] = "/var/run/docker.sock";
CurlHandler
could then check for this property and set CURLOPT_UNIX_SOCKET_PATH
using Interop.Http.EasySetOptionString
.
An application or library developer using this feature could easily create extension methods on HttpClient
to give themselves a nicer syntax.
If that API would be acceptable, I'd be happy to have a go at implementing it.
Thoughts?