Skip to content

Commit

Permalink
use of triggerUserOutboundEvent to reset requestSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudrani committed Aug 30, 2019
1 parent 2613958 commit cf7232d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 3 additions & 4 deletions Sources/KituraNet/HTTP/HTTPRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ internal class HTTPRequestHandler: ChannelInboundHandler, RemovableChannelHandle
serverRequest.buffer!.byteBuffer.writeBuffer(&buffer)
}
case .end:
let resetRequestSize = 0
serverResponse = HTTPServerResponse(channel: context.channel, handler: self)
//Make sure we use the latest delegate registered with the server
DispatchQueue.global().async {
Expand All @@ -107,14 +108,12 @@ internal class HTTPRequestHandler: ChannelInboundHandler, RemovableChannelHandle
Monitor.delegate?.started(request: serverRequest, response: serverResponse)
delegate.handle(request: serverRequest, response: serverResponse)
}
self.userInboundEventTriggered(context: context, event: resetRequestSize)
}
}

//IdleStateEvents are received on this method
public func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
if event is IdleStateHandler.IdleStateEvent {
_ = context.close()
}
context.triggerUserOutboundEvent(event, promise: nil)
}

public func channelReadComplete(context: ChannelHandlerContext) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/KituraNet/HTTP/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ public class HTTPServer: Server {
})
return channel.pipeline.configureHTTPServerPipeline(withServerUpgrade: config, withErrorHandling: true).flatMap {
if let nioSSLServerHandler = self.createNIOSSLServerHandler() {
_ = channel.pipeline.addHandler(nioSSLServerHandler, position: .first)
return channel.pipeline.addHandler(nioSSLServerHandler, position: .first)
}
_ = channel.pipeline.addHandler(serverConfigurationHandler, position: .first)
return channel.pipeline.addHandler(httpHandler)
}
return channel.eventLoop.makeSucceededFuture(()) } .flatMap {
return channel.pipeline.addHandler(serverConfigurationHandler, position: .first) }.flatMap {
return channel.pipeline.addHandler(httpHandler)}
}

let listenerDescription: String
Expand Down
6 changes: 2 additions & 4 deletions Sources/KituraNet/HTTP/HTTPServerConfigurationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ internal class HTTPServerConfigurationHandler: ChannelDuplexHandler {
context.fireChannelRead(wrapInboundOut(data))
}

public func channelReadComplete(context: ChannelHandlerContext){
requestSize = 0
context.fireChannelReadComplete()
public func triggerUserOutboundEvent(context: ChannelHandlerContext, event: Any, promise: EventLoopPromise<Void>?) {
requestSize = event as? Int ?? 0
}

public func channelActive(context: ChannelHandlerContext) {
_ = server.connectionCount.add(1)
if let connectionLimit1 = connectionLimit {
Expand Down

0 comments on commit cf7232d

Please sign in to comment.