Skip to content

Commit 4e2a065

Browse files
committed
Exposing HostName property for .NET DriverService class
Previously, the host name for a DriverService was hard-coded to be "localhost." This is normally acceptable, as a DriverService is only intended to be used locally, and most executables that are represented by a DriverService (chromedriver, geckodriver, IEDriverServer.exe, etc.) do not even allow connections from external machines. However, there is a legitimate use case (.NET Standard 2.0) where a local IP address ("127.0.0.1" or "::1") is preferrable to using the "localhost" moniker. This HostName property allows the user to specify that IP address. Note that the property defaults to "localhost," preserving previous behavior.
1 parent 792388f commit 4e2a065

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dotnet/src/webdriver/DriverService.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="DriverService.cs" company="WebDriver Committers">
1+
// <copyright file="DriverService.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -34,6 +34,7 @@ public abstract class DriverService : ICommandServer
3434
{
3535
private string driverServicePath;
3636
private string driverServiceExecutableName;
37+
private string driverServiceHostName = "localhost";
3738
private int driverServicePort;
3839
private bool silent;
3940
private bool hideCommandPromptWindow;
@@ -75,7 +76,21 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
7576
/// </summary>
7677
public Uri ServiceUrl
7778
{
78-
get { return new Uri(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}", this.driverServicePort)); }
79+
get { return new Uri(string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}", this.driverServiceHostName, this.driverServicePort)); }
80+
}
81+
82+
/// <summary>
83+
/// Gets or sets the host name of the service. Defaults to "localhost."
84+
/// </summary>
85+
/// <remarks>
86+
/// Most driver service executables do not allow connections from remote
87+
/// (non-local) machines. This property can be used as a workaround so
88+
/// that an IP address (like "127.0.0.1" or "::1") can be used instead.
89+
/// </remarks>
90+
public string HostName
91+
{
92+
get { return this.driverServiceHostName; }
93+
set { this.driverServiceHostName = value; }
7994
}
8095

8196
/// <summary>

0 commit comments

Comments
 (0)