From 7b49cc8d8f85cdd487d648ea29794230b14be3b4 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 16 Jan 2024 17:00:59 +0000 Subject: [PATCH] Fix up after changes to Hummingbird --- hello/Package.swift | 1 + hello/Tests/AppTests/AppTests.swift | 2 +- http2/Sources/App/Application+build.swift | 7 ++++--- http2/Tests/AppTests/AppTests.swift | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hello/Package.swift b/hello/Package.swift index 6c7a2957..53044228 100644 --- a/hello/Package.swift +++ b/hello/Package.swift @@ -29,6 +29,7 @@ let package = Package( name: "AppTests", dependencies: [ .byName(name: "App"), + .product(name: "Hummingbird", package: "hummingbird"), .product(name: "HummingbirdXCT", package: "hummingbird"), ] ), diff --git a/hello/Tests/AppTests/AppTests.swift b/hello/Tests/AppTests/AppTests.swift index 07d1438b..b9f10ab5 100644 --- a/hello/Tests/AppTests/AppTests.swift +++ b/hello/Tests/AppTests/AppTests.swift @@ -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") } } } diff --git a/http2/Sources/App/Application+build.swift b/http2/Sources/App/Application+build.swift index b3aa4e2a..e8f76a03 100644 --- a/http2/Sources/App/Application+build.swift +++ b/http2/Sources/App/Application+build.swift @@ -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 } @@ -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")" } diff --git a/http2/Tests/AppTests/AppTests.swift b/http2/Tests/AppTests/AppTests.swift index 94760d65..bda9aae2 100644 --- a/http2/Tests/AppTests/AppTests.swift +++ b/http2/Tests/AppTests/AppTests.swift @@ -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") } } }