Skip to content

Commit

Permalink
Proxy config to ChromeForTestingClient added (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklausburren committed Aug 9, 2023
1 parent 0db1785 commit e0ceb46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions WebDriverManager/Clients/ChromeForTestingClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
Expand All @@ -14,27 +15,40 @@ public static class ChromeForTestingClient
PropertyNameCaseInsensitive = true
};

private static readonly HttpClient _httpClient;
private static HttpClient _httpClient;

static ChromeForTestingClient()
private static HttpClient HttpClient
{
_httpClient = new HttpClient
get
{
BaseAddress = new Uri(BaseUrl)
};
var handler = new HttpClientHandler
{
UseProxy = Proxy != null,
Proxy = Proxy
};

_httpClient = new HttpClient(handler)
{
BaseAddress = new Uri(BaseUrl)
};

return _httpClient;
}
}

public static IWebProxy Proxy { get; set; }

public static ChromeVersions GetKnownGoodVersionsWithDownloads()
{
return GetResultFromHttpTask<ChromeVersions>(
_httpClient.GetAsync("known-good-versions-with-downloads.json")
HttpClient.GetAsync("known-good-versions-with-downloads.json")
);
}

public static ChromeVersions GetLastKnownGoodVersions()
{
return GetResultFromHttpTask<ChromeVersions>(
_httpClient.GetAsync("last-known-good-versions-with-downloads.json")
HttpClient.GetAsync("last-known-good-versions-with-downloads.json")
);
}

Expand Down
2 changes: 2 additions & 0 deletions WebDriverManager/DriverManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using WebDriverManager.Clients;
using WebDriverManager.DriverConfigs;
using WebDriverManager.Helpers;
using WebDriverManager.Services;
Expand Down Expand Up @@ -36,6 +37,7 @@ public DriverManager(IBinaryService binaryService, IVariableService variableServ
public DriverManager WithProxy(IWebProxy proxy)
{
_binaryService = new BinaryService {Proxy = proxy};
ChromeForTestingClient.Proxy = proxy;
WebRequest.DefaultWebProxy = proxy;
return this;
}
Expand Down

0 comments on commit e0ceb46

Please sign in to comment.