Skip to content

Commit

Permalink
Fixes after routerbuilder changes (#8)
Browse files Browse the repository at this point in the history
* Fix after router builder changes

* Use separate router for web sockets

* Use hummingbird branch feature/run-router-first

* Use main branch

* Increase autoping test timeout

* Use codecov@v3 action

* Use hummingbird v1.0.0-rc
  • Loading branch information
adam-fowler committed Jan 17, 2023
1 parent 27a0994 commit 157c9cd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
-ignore-filename-regex="\/Tests\/" \
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
- name: Upload to codecov.io
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
file: info.lcov
linux:
Expand All @@ -57,6 +57,6 @@ jobs:
-ignore-filename-regex="\/Tests\/" \
-instr-profile .build/debug/codecov/default.profdata > info.lcov
- name: Upload to codecov.io
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
file: info.lcov
4 changes: 2 additions & 2 deletions Package.swift
Expand Up @@ -12,8 +12,8 @@ let package = Package(
.library(name: "HummingbirdWSCore", targets: ["HummingbirdWSCore"]),
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird-core.git", from: "1.0.0-alpha"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "1.0.0-alpha"),
.package(url: "https://github.com/hummingbird-project/hummingbird-core.git", from: "1.0.0-rc"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "1.0.0-rc"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.1"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.5.0"),
.package(url: "https://github.com/swift-extras/swift-extras-base64.git", from: "0.5.0"),
Expand Down
6 changes: 3 additions & 3 deletions Sources/HummingbirdWebSocket/Application+WebSocket.swift
Expand Up @@ -37,7 +37,7 @@ extension HBApplication {
)
request.webSocketTestShouldUpgrade = true
return responder.respond(to: request).flatMapThrowing {
if $0.webSocketShouldUpgrade == true {
if $0.status == .ok {
return $0.headers
}
throw HBHTTPError(.badRequest)
Expand All @@ -54,11 +54,11 @@ extension HBApplication {
_ = responder.respond(to: request)
}
)
self.routerGroup = .init(router: self.application.router)
self.routerGroup = .init(router: HBRouterBuilder())
self.application.lifecycle.register(
label: "WebSockets",
start: .sync {
self.responder = self.application.middleware.constructResponder(finalResponder: application.router)
self.responder = self.routerGroup.router.buildRouter()
},
shutdown: .sync {}
)
Expand Down
8 changes: 0 additions & 8 deletions Sources/HummingbirdWebSocket/Request+WebSocket.swift
Expand Up @@ -28,11 +28,3 @@ extension HBRequest {
set { self.extensions.set(\.webSocketTestShouldUpgrade, value: newValue) }
}
}

extension HBResponse {
/// Can we upgrade to a web socket connection?
var webSocketShouldUpgrade: Bool? {
get { self.extensions.get(\.webSocketShouldUpgrade) }
set { self.extensions.set(\.webSocketShouldUpgrade, value: newValue) }
}
}
8 changes: 3 additions & 5 deletions Sources/HummingbirdWebSocket/WebSocketRouterGroup.swift
Expand Up @@ -16,10 +16,10 @@ import Hummingbird

/// Router Group for adding WebSocket connections to
public struct HBWebSocketRouterGroup {
let router: HBRouter
let router: HBRouterBuilder
let middlewares: HBMiddlewareGroup

init(router: HBRouter) {
init(router: HBRouterBuilder) {
self.router = router
self.middlewares = .init()
}
Expand All @@ -46,9 +46,7 @@ public struct HBWebSocketRouterGroup {
return request.body.consumeBody(on: request.eventLoop).flatMap { buffer in
request.body = .byteBuffer(buffer)
return shouldUpgrade(request).map { headers in
var response = HBResponse(status: .ok, headers: headers ?? [:])
response.webSocketShouldUpgrade = true
return response
return HBResponse(status: .ok, headers: headers ?? [:])
}
}
} else if let webSocket = request.webSocket {
Expand Down
2 changes: 1 addition & 1 deletion Tests/HummingbirdWebSocketTests/WebSocketTests.swift
Expand Up @@ -242,7 +242,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
func testAutoPing() throws {
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { XCTAssertNoThrow(try elg.syncShutdownGracefully()) }
let promise = TimeoutPromise(eventLoop: elg.next(), timeout: .seconds(10))
let promise = TimeoutPromise(eventLoop: elg.next(), timeout: .seconds(30))
var count = 0

let app = try self.setupClientAndServer(
Expand Down

0 comments on commit 157c9cd

Please sign in to comment.