Skip to content

fix!: Represent TCP port as UInt16 #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CRTClientEngine: HTTPClient {
private struct ConnectionPoolID: Hashable {
private let protocolType: URIScheme?
private let host: String
private let port: Int16
private let port: UInt16

init(endpoint: Endpoint) {
self.protocolType = endpoint.uri.scheme
Expand Down
12 changes: 6 additions & 6 deletions Sources/Smithy/URI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public struct URI: Hashable {
public let scheme: URIScheme
public let path: String
public let host: String
public let port: Int16?
public var defaultPort: Int16 {
Int16(scheme.port)
public let port: UInt16?
public var defaultPort: UInt16 {
UInt16(scheme.port)
}
public let queryItems: [URIQueryItem]
public let username: String?
Expand All @@ -29,7 +29,7 @@ public struct URI: Hashable {
fileprivate init(scheme: URIScheme,
path: String,
host: String,
port: Int16?,
port: UInt16?,
queryItems: [URIQueryItem],
username: String? = nil,
password: String? = nil,
Expand Down Expand Up @@ -122,7 +122,7 @@ public final class URIBuilder {
}

@discardableResult
public func withPort(_ value: Int16?) -> URIBuilder {
public func withPort(_ value: UInt16?) -> URIBuilder {
self.urlComponents.port = value.map { Int($0) }
return self
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public final class URIBuilder {
return URI(scheme: URIScheme(rawValue: self.urlComponents.scheme!)!,
path: self.urlComponents.percentEncodedPath,
host: self.urlComponents.percentEncodedHost!,
port: self.urlComponents.port.map { Int16($0) },
port: self.urlComponents.port.map { UInt16($0) },
queryItems: self.urlComponents.percentEncodedQueryItems?.map {
URIQueryItem(name: $0.name, value: $0.value)
} ?? [],
Expand Down
4 changes: 2 additions & 2 deletions Sources/SmithyHTTPAPI/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct Endpoint: Hashable {
public var queryItems: [URIQueryItem] { uri.queryItems }
public var path: String { uri.path }
public var host: String { uri.host }
public var port: Int16? { uri.port }
public var port: UInt16? { uri.port }
public var url: URL? { uri.url }
private let properties: [String: AnyHashable]

Expand Down Expand Up @@ -54,7 +54,7 @@ public struct Endpoint: Hashable {

public init(host: String,
path: String = "/",
port: Int16 = 443,
port: UInt16 = 443,
queryItems: [URIQueryItem]? = nil,
headers: Headers = Headers(),
protocolType: URIScheme? = .https) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SmithyHTTPAPI/HTTPRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public final class HTTPRequestBuilder: RequestMessageBuilder {
public private(set) var path: String = "/"
public private(set) var body: ByteStream = .noStream
public private(set) var queryItems = [URIQueryItem]()
public private(set) var port: Int16?
public private(set) var port: UInt16?
public private(set) var protocolType: URIScheme = .https
public private(set) var trailingHeaders: Headers = Headers()

Expand Down Expand Up @@ -242,7 +242,7 @@ public final class HTTPRequestBuilder: RequestMessageBuilder {
}

@discardableResult
public func withPort(_ value: Int16?) -> HTTPRequestBuilder {
public func withPort(_ value: UInt16?) -> HTTPRequestBuilder {
self.port = value
return self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ExpectedSdkHttpRequestBuilder {
var queryItems = [URIQueryItem]()
var forbiddenQueryItems = [URIQueryItem]()
var requiredQueryItems = [URIQueryItem]()
var port: Int16 = 443
var port: UInt16 = 443
var protocolType: URIScheme = .https

// We follow the convention of returning the builder object
Expand Down Expand Up @@ -127,7 +127,7 @@ public class ExpectedSdkHttpRequestBuilder {
}

@discardableResult
public func withPort(_ value: Int16) -> ExpectedSdkHttpRequestBuilder {
public func withPort(_ value: UInt16) -> ExpectedSdkHttpRequestBuilder {
self.port = value
return self
}
Expand Down
Loading