KestrunHostMapExtensions.TryParseEndpointSpec method
Tries to parse an endpoint specification string into its components: host, port, and HTTPS flag.
public static bool TryParseEndpointSpec(string spec, out string host, out int port, out bool? https)
| parameter | description |
|---|---|
| spec | The endpoint specification string. |
| host | The host component. |
| port | The port component. |
| https | Indicates HTTPS (true) or HTTP (false) when the scheme is explicitly specified via a full URL. For host:port forms where no scheme information is available the value is null. |
Return Value
true if parsing succeeds; otherwise false and host will be string.Empty and port0.
Remarks
Accepted formats (in priority order):
- Full URL:
https://host:port,http://host:port, IPv6 literal allowed in brackets; if the port is omitted the default (80/443) is inferred. - Bracketed IPv6 host & port:
[::1]:5000,[2001:db8::1]:8080. - Host or IPv4 with port:
localhost:5000,127.0.0.1:8080,example.com:443.
Unsupported / rejected examples: non http(s) schemes (e.g. ftp://), missing port in host:port form, empty port (https://localhost:), malformed IPv6 without brackets.
See Also
- class KestrunHostMapExtensions
- namespace Kestrun.Hosting