Skip to content

Commit

Permalink
Fixing diagnostics image for 1.1 (#5018)
Browse files Browse the repository at this point in the history
Diagnostics image 1.1 currently fails for WebSockets when we add a proxy. But 1.2 works for this case. I copy pasted from 1.2 code to 1.1, since we were doing it in a different way in 1.2. I tested it with a proxy, and it works.
  • Loading branch information
dylanbronson committed May 21, 2021
1 parent 3629d72 commit 6b32f3c
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions edge-modules/iotedge-diagnostics-dotnet/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Diagnostics
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -80,24 +81,44 @@ static async Task EdgeAgent(string managementUri)

static async Task Iothub(string hostname, string port, string proxy)
{
if (proxy != null)
if (port == "443")
{
Uri proxyUri = new Uri(proxy);
IProxyClient proxyClient = MakeProxy(proxyUri);
var httpClientHandler = new HttpClientHandler();

// Setup timeouts
proxyClient.ReceiveTimeout = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
proxyClient.SendTimeout = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
if (proxy != null)
{
Environment.SetEnvironmentVariable("https_proxy", proxy);
}

// Get TcpClient to futher work
var client = proxyClient.CreateConnection(hostname, int.Parse(port));
client.GetStream();
var httpClient = new HttpClient(httpClientHandler);
var logsUrl = string.Format("https://{0}/devices/0000/modules", hostname);
var httpRequest = new HttpRequestMessage(HttpMethod.Get, logsUrl);
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead);
}
else
{
TcpClient client = new TcpClient();
await client.ConnectAsync(hostname, int.Parse(port));
client.GetStream();
// The current rust code never put proxy parameter when port is != than 443.
// So the code below is never exercised. It was put there to avoid silently ignoring the proxy
// if the rust code is changed.
if (proxy != null)
{
Uri proxyUri = new Uri(proxy);
IProxyClient proxyClient = MakeProxy(proxyUri);

// Setup timeouts
proxyClient.ReceiveTimeout = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
proxyClient.SendTimeout = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;

// Get TcpClient to futher work
var client = proxyClient.CreateConnection(hostname, int.Parse(port));
client.GetStream();
}
else
{
TcpClient client = new TcpClient();
await client.ConnectAsync(hostname, int.Parse(port));
client.GetStream();
}
}
}

Expand Down

0 comments on commit 6b32f3c

Please sign in to comment.