From 064c5b02fc544ecb350cae32e73da3162c0bee70 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Mon, 5 Jun 2023 13:41:44 -0700 Subject: [PATCH] Allow specifying port in host string in `NIOHTTPClient` Resolves https://github.com/bufbuild/connect-swift/issues/131. --- Libraries/ConnectNIO/Public/NIOHTTPClient.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/ConnectNIO/Public/NIOHTTPClient.swift b/Libraries/ConnectNIO/Public/NIOHTTPClient.swift index 28599f90..88393107 100644 --- a/Libraries/ConnectNIO/Public/NIOHTTPClient.swift +++ b/Libraries/ConnectNIO/Public/NIOHTTPClient.swift @@ -49,14 +49,16 @@ open class NIOHTTPClient: Connect.HTTPClientInterface { /// /// - parameter host: Target host (e.g., `https://buf.build`). /// - parameter port: Port to use for the connection. A default is provided based on whether a - /// secure connection is being established to the host via HTTPS. + /// secure connection is being established to the host via HTTPS. If this + /// parameter is omitted and the `host` parameter includes a port + /// (e.g., `https://buf.build:8080`), the host's port will be used. /// - parameter timeout: Optional timeout after which to terminate requests/streams if no /// activity has occurred in the request or response path. public init(host: String, port: Int? = nil, timeout: TimeInterval? = nil) { let baseURL = URL(string: host)! let useSSL = baseURL.scheme?.lowercased() == "https" self.host = baseURL.host! - self.port = port ?? (useSSL ? 443 : 80) + self.port = port ?? baseURL.port ?? (useSSL ? 443 : 80) self.timeout = timeout self.useSSL = useSSL }