Skip to content

Commit

Permalink
Remove crash point
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Aug 24, 2023
1 parent 11dd442 commit 4f028cb
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Sources/Vapor/HTTP/Server/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private final class HTTPServerConnection: Sendable {
}

// Set the handlers that are applied to the accepted Channels
.childChannelInitializer { [weak application] channel in
.childChannelInitializer { [unowned application] channel in
// add TLS handlers if configured
if var tlsConfiguration = configuration.tlsConfiguration {
// prioritize http/2
Expand All @@ -376,15 +376,11 @@ private final class HTTPServerConnection: Sendable {
configuration.logger.error("Could not configure TLS: \(error)")
return channel.close(mode: .all)
}
let applicationBox = NIOLockedValueBox(application)
return channel.pipeline.addHandler(tlsHandler).flatMap { _ in
channel.configureHTTP2SecureUpgrade(h2ChannelConfigurator: { channel in
channel.configureHTTP2Pipeline(
mode: .server,
inboundStreamInitializer: { channel in
guard let application = applicationBox.withLockedValue({ $0 }) else {
fatalError("Application has been deinitialized")
}
return channel.pipeline.addVaporHTTP2Handlers(
application: application,
responder: responder,
Expand All @@ -393,9 +389,6 @@ private final class HTTPServerConnection: Sendable {
}
).map { _ in }
}, http1ChannelConfigurator: { channel in
guard let application = applicationBox.withLockedValue({ $0 }) else {
fatalError("Application has been deinitialized")
}
return channel.pipeline.addVaporHTTP1Handlers(
application: application,
responder: responder,
Expand All @@ -408,7 +401,7 @@ private final class HTTPServerConnection: Sendable {
fatalError("Plaintext HTTP/2 (h2c) not yet supported.")
}
return channel.pipeline.addVaporHTTP1Handlers(
application: application!,
application: application,
responder: responder,
configuration: configuration
)
Expand Down

0 comments on commit 4f028cb

Please sign in to comment.