From 4283ebe9943e73b6c74ea48bb3fb9b52d1a9cc67 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Thu, 18 Apr 2024 14:07:24 +0100 Subject: [PATCH] Minor changes to HTTP channel lhandler (#417) --- Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift | 5 +++-- Sources/HummingbirdCore/Server/HTTP/HTTPChannelHandler.swift | 5 +---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift b/Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift index 293a9f5c9..6c2d6e224 100644 --- a/Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift +++ b/Sources/HummingbirdCore/Server/HTTP/HTTP1Channel.swift @@ -46,8 +46,9 @@ public struct HTTP1Channel: ServerChildChannel, HTTPChannelHandler { [HTTPUserEventHandler(logger: logger)] return channel.eventLoop.makeCompletedFuture { try channel.pipeline.syncOperations.configureHTTPServerPipeline( - withPipeliningAssistance: false, - withErrorHandling: true + withPipeliningAssistance: false, // HTTP is pipelined by NIOAsyncChannel + withErrorHandling: true, + withOutboundHeaderValidation: false // Swift HTTP Types are already doing this validation ) try channel.pipeline.syncOperations.addHandlers(childChannelHandlers) return try NIOAsyncChannel( diff --git a/Sources/HummingbirdCore/Server/HTTP/HTTPChannelHandler.swift b/Sources/HummingbirdCore/Server/HTTP/HTTPChannelHandler.swift index 0418b5e70..14e97715a 100644 --- a/Sources/HummingbirdCore/Server/HTTP/HTTPChannelHandler.swift +++ b/Sources/HummingbirdCore/Server/HTTP/HTTPChannelHandler.swift @@ -30,7 +30,6 @@ public protocol HTTPChannelHandler: ServerChildChannel { @usableFromInline enum HTTPChannelError: Error { case unexpectedHTTPPart(HTTPRequestPart) - case closeConnection } enum HTTPState: Int, Sendable { @@ -75,7 +74,7 @@ extension HTTPChannelHandler { throw error } if request.headers[.connection] == "close" { - throw HTTPChannelError.closeConnection + return } // set to idle unless it is cancelled then exit guard processingRequest.exchange(.idle) == .processing else { break } @@ -112,8 +111,6 @@ extension HTTPChannelHandler { } onCancel: { asyncChannel.channel.close(mode: .input, promise: nil) } - } catch HTTPChannelError.closeConnection { - // channel is being closed because we received a connection: close header } catch { // we got here because we failed to either read or write to the channel logger.trace("Failed to read/write to Channel. Error: \(error)")