Skip to content

Commit

Permalink
Set Responder to be Generic variable
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 31, 2023
1 parent e795612 commit 0ad5170
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Sources/Hummingbird/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public final class HBApplicationContext: Sendable {
/// try await app.buildAndRun()
/// ```
/// Editing the application builder setup after calling `build` will produce undefined behaviour.
public struct HBApplication<RequestContext: HBRequestContext> {
public struct HBApplication<Responder: HBResponder> {
// MARK: Member variables

/// event loop group used by application
public let eventLoopGroup: EventLoopGroup
/// thread pool used by application
public let threadPool: NIOThreadPool
/// routes requests to requestResponders based on URI
public let responder: any HBResponder<RequestContext>
public let responder: Responder
/// Configuration
public var configuration: HBApplicationConfiguration
/// Logger
Expand All @@ -109,7 +109,7 @@ public struct HBApplication<RequestContext: HBRequestContext> {

/// Initialize new Application
public init(
responder: any HBResponder<RequestContext>,
responder: Responder,
configuration: HBApplicationConfiguration = HBApplicationConfiguration(),
threadPool: NIOThreadPool = .singleton,
eventLoopGroupProvider: EventLoopGroupProvider = .singleton
Expand Down Expand Up @@ -166,7 +166,7 @@ extension HBApplication: Service {
decoder: self.decoder
)
let dateCache = HBDateCache()
let responder = Responder(
let responder = HTTPResponder(
responder: self.responder,
applicationContext: context,
dateCache: dateCache
Expand Down
6 changes: 3 additions & 3 deletions Sources/Hummingbird/Server/Application+HTTPResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import NIOCore
import NIOHTTP1

extension HBApplication {
struct Responder: HBHTTPResponder {
let responder: any HBResponder<RequestContext>
struct HTTPResponder: HBHTTPResponder {
let responder: Responder
let applicationContext: HBApplicationContext
let dateCache: HBDateCache

Expand All @@ -34,7 +34,7 @@ extension HBApplication {
head: request.head,
body: request.body
)
let context = RequestContext(
let context = Responder.Context(
applicationContext: self.applicationContext,
channel: context.channel,
logger: loggerWithRequestId(self.applicationContext.logger)
Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdXCT/Application+XCT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension HBApplication {
}
}

extension HBApplication where RequestContext: HBTestRouterContextProtocol {
extension HBApplication where Responder.Context: HBTestRouterContextProtocol {
// MARK: Initialization

/// Creates a version of `HBApplication` that can be used for testing code
Expand Down
6 changes: 3 additions & 3 deletions Sources/HummingbirdXCT/HBXCTLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ServiceLifecycle
import XCTest

/// Test using a live server
final class HBXCTLive<RequestContext: HBRequestContext>: HBXCTApplication {
final class HBXCTLive<Responder: HBResponder>: HBXCTApplication {
struct Client: HBXCTClientProtocol {
let client: HBXCTClient

Expand All @@ -42,7 +42,7 @@ final class HBXCTLive<RequestContext: HBRequestContext>: HBXCTApplication {
}
}

init(app: HBApplication<RequestContext>) {
init(app: HBApplication<Responder>) {
var app = app
app.configuration = app.configuration.with(address: .hostname("localhost", port: 0))
let promise = Promise<Int>()
Expand Down Expand Up @@ -86,7 +86,7 @@ final class HBXCTLive<RequestContext: HBRequestContext>: HBXCTApplication {
await self.promise.complete(channel.localAddress!.port!)
}

let application: HBApplication<RequestContext>
let application: HBApplication<Responder>
let promise: Promise<Int>
let timeout: TimeAmount
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/HummingbirdXCT/HBXCTRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public struct HBTestRouterContext: HBTestRouterContextProtocol, HBRemoteAddressR
}

/// Test sending values to requests to router. This does not setup a live server
struct HBXCTRouter<RequestContext: HBTestRouterContextProtocol>: HBXCTApplication {
struct HBXCTRouter<Responder: HBResponder>: HBXCTApplication where Responder.Context: HBTestRouterContextProtocol {
let eventLoopGroup: EventLoopGroup
let context: HBApplicationContext
let responder: any HBResponder<RequestContext>
let responder: Responder

init(app: HBApplication<RequestContext>) {
init(app: HBApplication<Responder>) {
self.eventLoopGroup = app.eventLoopGroup
self.context = HBApplicationContext(
threadPool: app.threadPool,
Expand All @@ -80,7 +80,7 @@ struct HBXCTRouter<RequestContext: HBTestRouterContextProtocol>: HBXCTApplicatio
/// resulting response back to XCT response type
struct Client: HBXCTClientProtocol {
let eventLoopGroup: EventLoopGroup
let responder: any HBResponder<RequestContext>
let responder: Responder
let applicationContext: HBApplicationContext

func execute(uri: String, method: HTTPMethod, headers: HTTPHeaders, body: ByteBuffer?) async throws -> HBXCTResponse {
Expand All @@ -91,10 +91,10 @@ struct HBXCTRouter<RequestContext: HBTestRouterContextProtocol>: HBXCTApplicatio
head: .init(version: .http1_1, method: method, uri: uri, headers: headers),
body: .byteBuffer(body)
)
let context = RequestContext(
let context = Responder.Context(
applicationContext: self.applicationContext,
eventLoop: eventLoop,
logger: HBApplication<RequestContext>.loggerWithRequestId(self.applicationContext.logger)
logger: HBApplication<Responder>.loggerWithRequestId(self.applicationContext.logger)
)
return self.responder.respond(to: request, context: context)
.flatMapErrorThrowing { error in
Expand Down

0 comments on commit 0ad5170

Please sign in to comment.