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
contentstringThe text.
defaultSchemestringThe scheme when nothing tells the protocol. The default is
http.preferHttpsWhenPort443boolMeant 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
textstringThe text.
defaultSchemestringThe scheme when nothing tells the protocol. The default is
http.preferHttpsWhenPort443boolMeant 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
FromUrl(Uri)
Reads a proxy endpoint from a URL such as socks5://user:password@host:1080.
public static ProxyEndPoint FromUrl(Uri uri)
Parameters
uriUriThe URL. Its scheme names the protocol, ignoring case. A URL with no port takes the port .NET gives its scheme, 80 for
httpand 443 forhttps, or else the protocol's default, 1080 for SOCKS. A query ofenabled=falseorenabled=0makes 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
proxyEndPointProxyEndPointThe 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
valuestringThe address, with or without a scheme, a port and credentials.
defaultsProxyEndPointDefaultsThe 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
socksandsocks5hread as SOCKS5 for it. A port that is the scheme's standard one, as 80 forhttp, counts as missing.
Returns
- Uri
The URL; with
enabled=falsein its query whendefaultssays 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
valuestringThe address.
defaultsProxyEndPointDefaultsThe values for the parts the address leaves out, or null.