Project updates from Template #1

Merged
javier merged 123 commits from project/update-from-template into main 2026-09-04 13:40:36 +00:00
Showing only changes of commit 52f092a4d7 - Show all commits
@@ -99,7 +99,7 @@ private extension PlaintextPostgresServer {
context: ChannelHandlerContext, context: ChannelHandlerContext,
data: NIOAny data: NIOAny
) { ) {
var buffer = unwrapInboundIn(data) let buffer = unwrapInboundIn(data)
switch state { switch state {
case .awaitingSSLRequest: case .awaitingSSLRequest:
@@ -107,13 +107,7 @@ private extension PlaintextPostgresServer {
// 'N', while a direct startup message (a client connecting with TLS disabled) is // 'N', while a direct startup message (a client connecting with TLS disabled) is
// answered straight away. // answered straight away.
guard buffer.getInteger(at: buffer.readerIndex + 4, as: Int32.self) == Self.sslRequestCode else { guard buffer.getInteger(at: buffer.readerIndex + 4, as: Int32.self) == Self.sslRequestCode else {
state = .established completeStartup(context: context)
context.writeAndFlush(
wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)),
promise: nil
)
return return
} }
@@ -128,17 +122,22 @@ private extension PlaintextPostgresServer {
promise: nil promise: nil
) )
case .awaitingStartup: case .awaitingStartup:
state = .established completeStartup(context: context)
context.writeAndFlush(
wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)),
promise: nil
)
case .established: case .established:
context.close(promise: nil) context.close(promise: nil)
} }
} }
/// Answers a startup message and marks the connection established.
private func completeStartup(context: ChannelHandlerContext) {
state = .established
context.writeAndFlush(
wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)),
promise: nil
)
}
// MARK: Helpers // MARK: Helpers
/// The reply completing a plaintext startup: `AuthenticationOk`, `BackendKeyData`, and /// The reply completing a plaintext startup: `AuthenticationOk`, `BackendKeyData`, and