In .NET Core I can send raw HTTP over a unix-domain socket, but I would like to use the HTTP handling classes in the library instead of hacking together my own HTTP handling.
Here is my current working-but-ugly code:
const string HTTP_REQUEST = "POST /containers/foo/kill?signal=SIGHUP HTTP/1.0\r\n" +
"Host: localhost\r\n" +
"Accept: */*\r\n\r\n";
socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
socket.ReceiveTimeout = 2000; // 2 seconds
var endpoint = new UnixDomainSocketEndPoint("/var/run/docker.sock");
socket.Connect(endpoint);
byte[] requestBytes = Encoding.ASCII.GetBytes(HTTP_REQUEST);
socket.Send(requestBytes);
byte[] recvBytes = new byte[1024];
int numBytes = socket.Receive(recvBytes, 1024, SocketFlags.None);
socket.Disconnect(false);
Console.WriteLine( Encoding.ASCII.GetString(recvBytes));
Is there a way to use the classes in the .NET Core library to handle the HTTP request and response over a unix-domain socket?
[edit] I'm aware in this particular use case that there is the Docker.DotNet library to achieve what I want, but the question in general is still worth asking.