Table of Contents

Class ProxyEndPointParser

Namespace
VpnHood.Core.Proxies.Management.Abstractions
Assembly
VpnHood.Core.Proxies.Management.Abstractions.dll

Provides the reading of proxy endpoints from URLs, from loosely written addresses, and from text.

public static class ProxyEndPointParser
Inheritance
ProxyEndPointParser
Inherited Members

Methods

ExtractFromContent(string, string, bool)

Finds the proxy addresses in a text, as ExtractFromText(string, string, bool) does, after splitting it into pieces at line ends, spaces, commas, quotes and brackets, so an address whose port follows a space, as 1.2.3.4 8080, is lost.

public static Uri[] ExtractFromContent(string content, string defaultScheme = "http", bool preferHttpsWhenPort443 = true)

Parameters

content string

The text.

defaultScheme string

The scheme when nothing tells the protocol. The default is http.

preferHttpsWhenPort443 bool

Meant to choose HTTPS for port 443 with no other sign; it changes nothing, as port 443 is taken for HTTPS either way. The default is true.

Returns

Uri[]

The addresses as URLs, in their order in the text.

ExtractFromText(string, string, bool)

Finds a proxy address in a line of text: a URL, an IPv4 or IPv6 address or a host name with a port, guessing the protocol from words such as socks5 and from the port.

public static Uri? ExtractFromText(string text, string defaultScheme = "http", bool preferHttpsWhenPort443 = true)

Parameters

text string

The text.

defaultScheme string

The scheme when nothing tells the protocol. The default is http.

preferHttpsWhenPort443 bool

Meant to choose HTTPS for port 443 with no other sign; it changes nothing, as port 443 is taken for HTTPS either way. The default is true.

Returns

Uri

The address as a URL, or null when none is found.

FromUrl(Uri)

Reads a proxy endpoint from a URL such as socks5://user:password@host:1080.

public static ProxyEndPoint FromUrl(Uri uri)

Parameters

uri Uri

The URL. Its scheme names the protocol, ignoring case. A URL with no port takes the port .NET gives its scheme, 80 for http and 443 for https, or else the protocol's default, 1080 for SOCKS. A query of enabled=false or enabled=0 makes the endpoint disabled.

Returns

ProxyEndPoint

The endpoint, with its escaped user name and password unescaped.

Exceptions

NotSupportedException

The scheme is no proxy protocol.

ArgumentException

The URL has no host.

Normalize(ProxyEndPoint)

Normalizes an endpoint whose host may be a whole address, such as socks5://proxy.example:1080: its parts fill the endpoint, and the endpoint's own values fill what it leaves out.

public static ProxyEndPoint Normalize(ProxyEndPoint proxyEndPoint)

Parameters

proxyEndPoint ProxyEndPoint

The endpoint.

Returns

ProxyEndPoint

A new endpoint, with the original's user name and password, trimmed, in place of any the host held.

Exceptions

ArgumentException

The host is empty or no valid address.

NotSupportedException

The address's scheme is no proxy protocol.

ParseHostToUrl(string, ProxyEndPointDefaults?)

Reads a loosely written proxy address, such as host:1080 or user:pass@host, into a URL.

public static Uri ParseHostToUrl(string value, ProxyEndPointDefaults? defaults)

Parameters

value string

The address, with or without a scheme, a port and credentials.

defaults ProxyEndPointDefaults

The values for the parts the address leaves out, or null; a missing port then takes the protocol's default (1080 for SOCKS, 8080 for HTTP, 443 for HTTPS), and socks and socks5h read as SOCKS5 for it. A port that is the scheme's standard one, as 80 for http, counts as missing.

Returns

Uri

The URL; with enabled=false in its query when defaults says the endpoint is disabled and the address's query does not say otherwise.

Exceptions

ArgumentException

The address is empty or not valid, or the address and the defaults give no scheme, or the scheme is no proxy protocol and no port is given; with a port, any scheme passes.

TryParseHostToUrl(string, ProxyEndPointDefaults?)

Reads a loosely written proxy address into a URL, as ParseHostToUrl(string, ProxyEndPointDefaults?) does, or gives null where that throws.

public static Uri? TryParseHostToUrl(string value, ProxyEndPointDefaults? defaults)

Parameters

value string

The address.

defaults ProxyEndPointDefaults

The values for the parts the address leaves out, or null.

Returns

Uri

The URL, or null.