Skip to content

Commit eab9f01

Browse files
yashdsarafclaude
andcommitted
3.1.0: arm64 + proxy passthrough for binary download
- GetBinaryName made public and adds Linux arm64 branch via RuntimeInformation.OSArchitecture. arm64 wins over alpine to match the Node SDK ordering. - BrowserStackTunnel.SetProxy(host, port) + proxyHost/proxyPort fields. - fetchSourceUrl builds HttpClientHandler with Proxy = WebProxy(host, port) when proxy is set. - downloadBinary sets WebClient.Proxy = WebProxy(host, port) when set. (Keeping WebClient; proxy plumbing on it is one line.) - Local.addArgs captures proxyHost/proxyPort on local fields in addition to appending to argumentString. Local.start calls tunnel.SetProxy(...) before DownloadVerifyAndRunBinary. - Test fixtures derive binaryName from BrowserStackTunnel.GetBinaryName() so arm64 CI hosts pick the right binary. Tracks LOC-6563. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3012a29 commit eab9f01

5 files changed

Lines changed: 45 additions & 7 deletions

File tree

BrowserStackLocal/BrowserStackLocal Unit Tests/BrowserStackTunnelTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class BrowserStackTunnelTests
1717
static readonly string homepath = os.Platform.ToString() == "Unix" ?
1818
Environment.GetFolderPath(Environment.SpecialFolder.Personal) :
1919
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
20-
static readonly string binaryName = os.Platform.ToString() == "Unix" ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe";
20+
static readonly string binaryName = BrowserStackTunnel.GetBinaryName();
2121
private TunnelClass tunnel;
2222
[TestMethod]
2323
public void TestInitialState()

BrowserStackLocal/BrowserStackLocal/BrowserStackLocal.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<Title>BrowserStackLocal</Title>
88
<Product>BrowserStackLocal</Product>
99
<Description>C# Bindings for BrowserStack Local</Description>
10-
<Version>3.0.0</Version>
11-
<AssemblyVersion>3.0.0</AssemblyVersion>
12-
<FileVersion>3.0.0</FileVersion>
10+
<Version>3.1.0</Version>
11+
<AssemblyVersion>3.1.0</AssemblyVersion>
12+
<FileVersion>3.1.0</FileVersion>
1313
<Authors>BrowserStack</Authors>
1414
<Company>BrowserStack</Company>
1515
<Copyright>Copyright © 2016</Copyright>

BrowserStackLocal/BrowserStackLocal/BrowserStackTunnel.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Net.Http;
1414
using System.Threading.Tasks;
15+
using System.Runtime.InteropServices;
1516
using Newtonsoft.Json;
1617

1718
namespace BrowserStack
@@ -27,6 +28,8 @@ public class BrowserStackTunnel : IDisposable
2728
private string sourceUrl = null;
2829
private bool isFallbackEnabled = false;
2930
private Exception downloadFailureException = null;
31+
private string proxyHost = null;
32+
private int proxyPort = 0;
3033

3134
static readonly string homepath = !IsWindows() ?
3235
Environment.GetFolderPath(Environment.SpecialFolder.Personal) :
@@ -77,13 +80,14 @@ static bool IsAlpine()
7780
return false;
7881
}
7982

80-
static string GetBinaryName()
83+
public static string GetBinaryName()
8184
{
8285
if (IsWindows()) return "BrowserStackLocal.exe";
8386
if (IsDarwin(uname)) return "BrowserStackLocal-darwin-x64";
8487

8588
if (IsLinux(uname))
8689
{
90+
if (IsArm64()) return "BrowserStackLocal-linux-arm64";
8791
if (Util.Is64BitOS())
8892
{
8993
return IsAlpine() ? "BrowserStackLocal-alpine" : "BrowserStackLocal-linux-x64";
@@ -94,6 +98,17 @@ static string GetBinaryName()
9498
return "BrowserStackLocal.exe";
9599
}
96100

101+
static bool IsArm64()
102+
{
103+
return RuntimeInformation.OSArchitecture == Architecture.Arm64;
104+
}
105+
106+
public virtual void SetProxy(string host, int port)
107+
{
108+
proxyHost = host;
109+
proxyPort = port;
110+
}
111+
97112
public virtual void addBinaryPath(string binaryAbsolute, string accessKey, bool fallbackEnabled = false, Exception failureException = null)
98113
{
99114
if (basePathsIndex == -1)
@@ -169,7 +184,14 @@ private string fetchSourceUrl(string accessKey)
169184
{
170185
var url = "https://local.browserstack.com/binary/api/v1/endpoint";
171186

172-
using (var client = new HttpClient())
187+
HttpClientHandler handler = new HttpClientHandler();
188+
if (!string.IsNullOrEmpty(proxyHost) && proxyPort > 0)
189+
{
190+
handler.Proxy = new WebProxy(proxyHost, proxyPort);
191+
handler.UseProxy = true;
192+
}
193+
194+
using (var client = new HttpClient(handler))
173195
{
174196
var data = new Dictionary<string, object>
175197
{
@@ -216,6 +238,10 @@ public void downloadBinary()
216238

217239
using (var client = new WebClient())
218240
{
241+
if (!string.IsNullOrEmpty(proxyHost) && proxyPort > 0)
242+
{
243+
client.Proxy = new WebProxy(proxyHost, proxyPort);
244+
}
219245
client.DownloadFile(sourceUrl + "/" + binaryName, this.binaryAbsolute);
220246
}
221247

BrowserStackLocal/BrowserStackLocal/Local.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class Local
1717
private string userAgent = "browserstack-local-csharp";
1818
private bool isFallbackEnabled = false;
1919
private Exception downloadFailureException = null;
20+
private string proxyHost = null;
21+
private int proxyPort = 0;
2022

2123
protected BrowserStackTunnel tunnel = null;
2224
private static KeyValuePair<string, string> emptyStringPair = new KeyValuePair<string, string>();
@@ -75,6 +77,15 @@ private void addArgs(string key, string value)
7577
}
7678
else
7779
{
80+
if (key.Equals("proxyHost"))
81+
{
82+
proxyHost = value;
83+
}
84+
else if (key.Equals("proxyPort"))
85+
{
86+
int.TryParse(value, out proxyPort);
87+
}
88+
7889
result = valueCommands.Find(pair => pair.Key == key);
7990
if (!result.Equals(emptyStringPair))
8091
{
@@ -226,6 +237,7 @@ public void start(List<KeyValuePair<string, string>> options)
226237
argumentString += "-logFile \"" + customLogPath + "\" ";
227238
argumentString += "--source \"c-sharp:" + bindingVersion + "\" ";
228239
tunnel.addBinaryArguments(argumentString);
240+
tunnel.SetProxy(proxyHost, proxyPort);
229241

230242
DownloadVerifyAndRunBinary();
231243
}

BrowserStackLocal/BrowserStackLocalIntegrationTests/IntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BrowserStackLocalIntegrationTests
1212
public class IntegrationTests
1313
{
1414
static readonly OperatingSystem os = Environment.OSVersion;
15-
static readonly string binaryName = os.Platform.ToString() == "Unix" ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal";
15+
static readonly string binaryName = BrowserStackTunnel.GetBinaryName().Replace(".exe", "");
1616
private static string username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
1717
private static string accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
1818

0 commit comments

Comments
 (0)