@@ -97,13 +97,15 @@ extension NIOHTTPServer {
9797 channel: any Channel ,
9898 asyncChannelConfiguration: NIOAsyncChannel < HTTPRequestPart , HTTPResponsePart > . Configuration
9999 ) -> EventLoopFuture < NIOAsyncChannel < HTTPRequestPart , HTTPResponsePart > > {
100- channel. pipeline. configureHTTPServerPipeline ( ) . flatMapThrowing {
101- try channel. pipeline. syncOperations. addHandler ( HTTP1ToHTTPServerCodec ( secure: false ) )
100+ channel. pipeline. addHandler ( LoggingHandler ( ) ) . flatMap {
101+ channel. pipeline. configureHTTPServerPipeline ( ) . flatMapThrowing {
102+ try channel. pipeline. syncOperations. addHandler ( HTTP1ToHTTPServerCodec ( secure: false ) )
102103
103- return try NIOAsyncChannel < HTTPRequestPart , HTTPResponsePart > (
104- wrappingChannelSynchronously: channel,
105- configuration: asyncChannelConfiguration
106- )
104+ return try NIOAsyncChannel < HTTPRequestPart , HTTPResponsePart > (
105+ wrappingChannelSynchronously: channel,
106+ configuration: asyncChannelConfiguration
107+ )
108+ }
107109 }
108110 }
109111
@@ -144,3 +146,38 @@ extension NIOHTTPServer {
144146 }
145147 }
146148}
149+
150+ import Runtime
151+ final class LoggingHandler : ChannelDuplexHandler , Sendable {
152+ typealias InboundIn = ByteBuffer
153+ typealias OutboundIn = ByteBuffer
154+
155+ func channelRead( context: ChannelHandlerContext , data: NIOAny ) {
156+ print ( " channelRead: \( self . unwrapInboundIn ( data) ) " )
157+ context. fireChannelRead ( data)
158+ }
159+
160+ func channelReadComplete( context: ChannelHandlerContext ) {
161+ print ( " channelReadComplete " )
162+ context. fireChannelReadComplete ( )
163+ }
164+
165+ func close( context: ChannelHandlerContext , mode: CloseMode , promise: EventLoopPromise < Void > ? ) {
166+ if #available( macOS 26 . 0 , * ) {
167+ print ( " close " , try ! Backtrace . capture ( ) . symbolicated ( ) ? . description)
168+ } else {
169+ // Fallback on earlier versions
170+ }
171+ context. close ( mode: mode, promise: promise)
172+ }
173+
174+ func flush( context: ChannelHandlerContext ) {
175+ print ( " flush " )
176+ context. flush ( )
177+ }
178+
179+ func write( context: ChannelHandlerContext , data: NIOAny , promise: EventLoopPromise < Void > ? ) {
180+ print ( " write: \( self . unwrapOutboundIn ( data) ) " )
181+ context. write ( data, promise: promise)
182+ }
183+ }
0 commit comments