Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy config to ChromeForTestingClient added #259

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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