Skip to content

Commit 13f6c73

Browse files
authored
Add PostgresConfiguration.ianaPortNumber with appropriate value. Use the property in place of the hardcoded value. (vapor#201)
1 parent bb1493e commit 13f6c73

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Sources/PostgresKit/PostgresConfiguration.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ public struct PostgresConfiguration {
1010
/// Optional `search_path` to set on new connections.
1111
public var searchPath: [String]?
1212

13-
internal var _hostname: String?
13+
/// IANA-assigned port number for PostgreSQL
14+
/// `UInt16(getservbyname("postgresql", "tcp").pointee.s_port).byteSwapped`
15+
public static var ianaPortNumber: Int { 5432 }
1416

17+
internal var _hostname: String?
1518

1619
public init?(url: String) {
1720
guard let url = URL(string: url) else {
@@ -31,7 +34,7 @@ public struct PostgresConfiguration {
3134
guard let hostname = url.host else {
3235
return nil
3336
}
34-
let port = url.port ?? 5432
37+
let port = url.port ?? Self.ianaPortNumber
3538

3639
let tlsConfiguration: TLSConfiguration?
3740
if url.query?.contains("ssl=true") == true || url.query?.contains("sslmode=require") == true {
@@ -68,7 +71,7 @@ public struct PostgresConfiguration {
6871

6972
public init(
7073
hostname: String,
71-
port: Int = 5432,
74+
port: Int = Self.ianaPortNumber,
7275
username: String,
7376
password: String? = nil,
7477
database: String? = nil,

Tests/PostgresKitTests/Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension PostgresConnection {
44
static func test(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
55
do {
66
let address: SocketAddress
7-
address = try .makeAddressResolvingHost(hostname, port: 5432)
7+
address = try .makeAddressResolvingHost(hostname, port: PostgresConfiguration.ianaPortNumber)
88
return connect(to: address, on: eventLoop).flatMap { conn in
99
return conn.authenticate(
1010
username: "vapor_username",
@@ -22,7 +22,7 @@ extension PostgresConfiguration {
2222
static var test: Self {
2323
.init(
2424
hostname: hostname,
25-
port: 5432,
25+
port: Self.ianaPortNumber,
2626
username: "vapor_username",
2727
password: "vapor_password",
2828
database: "vapor_database"

0 commit comments

Comments
 (0)