Skip to content

Commit

Permalink
Fix Linux Check (#3950)
Browse files Browse the repository at this point in the history
When checking the workload api from a container, Windows needs to remove a leading /. Linux doesn't, and removing the / caused it to incorrectly fail. 

To fix this, the Uri class is used to correctly localize the path.
  • Loading branch information
lfitchett authored Nov 11, 2020
1 parent 3b3dfcc commit dfa0967
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions edge-modules/iotedge-diagnostics-dotnet/src/GetSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ namespace Diagnostics
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;

public class GetSocket
{
public static string GetSocketResponse(string server, string endpoint)
{
Uri uri = new Uri(server);
string request = $"GET {endpoint} HTTP/1.1\r\nHost: {server}\r\nConnection: Close\r\n\r\n";
byte[] bytesSent = Encoding.ASCII.GetBytes(request);
byte[] bytesReceived = new byte[256];
server = server.Replace("unix://", string.Empty).Trim('/');

// Create a socket connection with the specified server and port.
using (Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP))
{
socket.Connect(new UnixDomainSocketEndPoint(server));
socket.Connect(new UnixDomainSocketEndPoint(uri.LocalPath));

// Send request to the server.
socket.Send(bytesSent, bytesSent.Length, 0);
Expand Down

0 comments on commit dfa0967

Please sign in to comment.