-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.x.x - Hello and HTTP2 examples (#43)
* Fix hello tests * HTTP2 * Update README * Update README * Update for changes on 2.x.x * Don’t export HBXCTAsyncHTTPClient * Update http2/Sources/App/Application+build.swift Co-authored-by: Joannis Orlandos <[email protected]> * Fix up after changes to Hummingbird --------- Co-authored-by: Joannis Orlandos <[email protected]>
- Loading branch information
1 parent
dd83013
commit a18dcc2
Showing
9 changed files
with
85 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
import App | ||
@testable import App | ||
import Hummingbird | ||
import HummingbirdXCT | ||
import XCTest | ||
|
||
final class AppTests: XCTestCase { | ||
func testApp() throws { | ||
let app = HBApplication(testing: .live) | ||
try app.configure() | ||
|
||
try app.XCTStart() | ||
defer { app.XCTStop() } | ||
|
||
try app.XCTExecute(uri: "/", method: .GET) { response in | ||
XCTAssertEqual(response.status, .ok) | ||
XCTAssertEqual(response.body.map { String(buffer: $0) }, "Hello") | ||
func testApp() async throws { | ||
let app = buildApplication(configuration: .init()) | ||
try await app.test(.router) { client in | ||
try await client.XCTExecute(uri: "/", method: .get) { response in | ||
XCTAssertEqual(response.status, .ok) | ||
XCTAssertEqual(String(buffer: response.body), "Hello") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Hummingbird | ||
import HummingbirdHTTP2 | ||
import Logging | ||
import NIOCore | ||
import NIOHTTPTypesHTTP2 | ||
|
||
public protocol AppArguments { | ||
var tlsConfiguration: TLSConfiguration { get throws } | ||
} | ||
|
||
struct ChannelRequestContext: HBRequestContext { | ||
init(allocator: ByteBufferAllocator, logger: Logger) { | ||
self.coreContext = .init(allocator: allocator, logger: logger) | ||
self.channel = nil | ||
} | ||
|
||
init(channel: Channel, logger: Logger) { | ||
self.coreContext = .init(allocator: channel.allocator, logger: logger) | ||
self.channel = channel | ||
} | ||
|
||
var hasHTTP2Handler: Bool { | ||
get async { | ||
if let channel = self.channel { | ||
return (try? await channel.pipeline.handler(type: HTTP2FramePayloadToHTTPServerCodec.self).get()) != nil | ||
} | ||
return false | ||
} | ||
} | ||
|
||
var coreContext: HBCoreRequestContext | ||
let channel: Channel? | ||
} | ||
|
||
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")" | ||
} | ||
|
||
let app = try HBApplication( | ||
router: router, | ||
server: .http2(tlsConfiguration: arguments.tlsConfiguration), | ||
configuration: configuration | ||
) | ||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters