Skip to content

Commit

Permalink
Fix up after changes to Hummingbird
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jan 17, 2024
1 parent a5fcf44 commit 7b49cc8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions hello/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let package = Package(
name: "AppTests",
dependencies: [
.byName(name: "App"),
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "HummingbirdXCT", package: "hummingbird"),
]
),
Expand Down
2 changes: 1 addition & 1 deletion hello/Tests/AppTests/AppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class AppTests: XCTestCase {
try await app.test(.router) { client in
try await client.XCTExecute(uri: "/", method: .get) { response in
XCTAssertEqual(response.status, .ok)
XCTAssertEqual(response.body.map { String(buffer: $0) }, "Hello")
XCTAssertEqual(String(buffer: response.body), "Hello")
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions http2/Sources/App/Application+build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public protocol AppArguments {
}

struct ChannelRequestContext: HBRequestContext {
init(eventLoop: EventLoop, allocator: ByteBufferAllocator, logger: Logger) {
self.coreContext = .init(eventLoop: eventLoop, allocator: allocator, logger: logger)
init(allocator: ByteBufferAllocator, logger: Logger) {
self.coreContext = .init(allocator: allocator, logger: logger)
self.channel = nil
}

init(channel: Channel, logger: Logger) {
self.coreContext = .init(eventLoop: channel.eventLoop, allocator: channel.allocator, logger: logger)
self.coreContext = .init(allocator: channel.allocator, logger: logger)
self.channel = channel
}

Expand All @@ -37,6 +37,7 @@ import Hummingbird
func buildApplication(arguments: some AppArguments, configuration: HBApplicationConfiguration) throws -> some HBApplicationProtocol {
let router = HBRouter(context: ChannelRequestContext.self)
router.get("/http") { _, context in
// return "Using http v\(request.head. == "h2" ? "2.0" : "1.1")"
return "Using http v\(await context.hasHTTP2Handler ? "2.0" : "1.1")"
}

Expand Down
4 changes: 2 additions & 2 deletions http2/Tests/AppTests/AppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ final class AppTests: XCTestCase {
try await app.test(.ahc(.https)) { client in
try await client.XCTExecute(uri: "/http", method: .get) { response in
XCTAssertEqual(response.status, .ok)
XCTAssertEqual(response.body.map { String(buffer: $0) }, "Using http v2.0")
XCTAssertEqual(String(buffer: response.body), "Using http v2.0")
}

try await client.XCTExecute(uri: "/http", method: .get) { response in
XCTAssertEqual(response.status, .ok)
XCTAssertEqual(response.body.map { String(buffer: $0) }, "Using http v2.0")
XCTAssertEqual(String(buffer: response.body), "Using http v2.0")
}
}
}
Expand Down

0 comments on commit 7b49cc8

Please sign in to comment.