From e0ceb469204b3102660e2e6e261c30aef9ff2035 Mon Sep 17 00:00:00 2001 From: Niklaus Burren Date: Wed, 9 Aug 2023 18:37:19 +0200 Subject: [PATCH] Proxy config to ChromeForTestingClient added (#259) --- .../Clients/ChromeForTestingClient.cs | 28 ++++++++++++++----- WebDriverManager/DriverManager.cs | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/WebDriverManager/Clients/ChromeForTestingClient.cs b/WebDriverManager/Clients/ChromeForTestingClient.cs index 0a40846..efa2a87 100644 --- a/WebDriverManager/Clients/ChromeForTestingClient.cs +++ b/WebDriverManager/Clients/ChromeForTestingClient.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; @@ -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( - _httpClient.GetAsync("known-good-versions-with-downloads.json") + HttpClient.GetAsync("known-good-versions-with-downloads.json") ); } public static ChromeVersions GetLastKnownGoodVersions() { return GetResultFromHttpTask( - _httpClient.GetAsync("last-known-good-versions-with-downloads.json") + HttpClient.GetAsync("last-known-good-versions-with-downloads.json") ); } diff --git a/WebDriverManager/DriverManager.cs b/WebDriverManager/DriverManager.cs index e85d254..d0f2cee 100644 --- a/WebDriverManager/DriverManager.cs +++ b/WebDriverManager/DriverManager.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Net; +using WebDriverManager.Clients; using WebDriverManager.DriverConfigs; using WebDriverManager.Helpers; using WebDriverManager.Services; @@ -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; }