Skip to content

Commit

Permalink
Make HTTPChannelHandler.responder immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Dec 16, 2023
1 parent 4366644 commit 39d9075
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct HTTP1Channel: HBChannelSetup, HTTPChannelHandler {
public typealias Value = NIOAsyncChannel<HTTPRequestPart, HTTPResponsePart>

public init(
responder: @escaping @Sendable (HBRequest, Channel) async throws -> HBResponse = { _, _ in throw HBHTTPError(.notImplemented) },
responder: @escaping @Sendable (HBRequest, Channel) async throws -> HBResponse,
additionalChannelHandlers: @escaping @Sendable () -> [any RemovableChannelHandler] = { [] }

Check warning on line 26 in Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift#L26

Added line #L26 was not covered by tests
) {
self.additionalChannelHandlers = additionalChannelHandlers
Expand Down Expand Up @@ -51,6 +51,6 @@ public struct HTTP1Channel: HBChannelSetup, HTTPChannelHandler {
await handleHTTP(asyncChannel: asyncChannel, logger: logger)
}

public var responder: @Sendable (HBRequest, Channel) async throws -> HBResponse
public let responder: @Sendable (HBRequest, Channel) async throws -> HBResponse
let additionalChannelHandlers: @Sendable () -> [any RemovableChannelHandler]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ServiceLifecycle
/// Protocol for HTTP channels
public protocol HTTPChannelHandler: HBChannelSetup {
typealias Responder = @Sendable (HBRequest, Channel) async throws -> HBResponse
var responder: Responder { get set }
var responder: Responder { get }
}

/// Internal error thrown when an unexpected HTTP part is received eg we didn't receive
Expand Down
7 changes: 2 additions & 5 deletions Sources/HummingbirdHTTP2/HTTP2Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ public struct HTTP2Channel: HTTPChannelHandler {
public typealias Value = EventLoopFuture<NIONegotiatedHTTPVersion<HTTP1Channel.Value, (NIOAsyncChannel<HTTP2Frame, HTTP2Frame>, NIOHTTP2Handler.AsyncStreamMultiplexer<HTTP1Channel.Value>)>>

private let sslContext: NIOSSLContext
private var http1: HTTP1Channel
private let http1: HTTP1Channel
private let additionalChannelHandlers: @Sendable () -> [any RemovableChannelHandler]
public var responder: @Sendable (HBRequest, Channel) async throws -> HBResponse {
get { http1.responder }
set { http1.responder = newValue }
}
public var responder: @Sendable (HBRequest, Channel) async throws -> HBResponse { http1.responder }

public init(
tlsConfiguration: TLSConfiguration,
Expand Down
3 changes: 1 addition & 2 deletions Sources/HummingbirdTLS/TLSChannelSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public struct TLSChannel<BaseChannel: HBChannelSetup>: HBChannelSetup {

extension TLSChannel: HTTPChannelHandler where BaseChannel: HTTPChannelHandler {
public var responder: @Sendable (HBRequest, Channel) async throws -> HBResponse {
get { baseChannel.responder }
set { baseChannel.responder = newValue }
baseChannel.responder

Check warning on line 35 in Sources/HummingbirdTLS/TLSChannelSetup.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HummingbirdTLS/TLSChannelSetup.swift#L35

Added line #L35 was not covered by tests
}
}

0 comments on commit 39d9075

Please sign in to comment.