From a43e98e8f4ec830a1d30fa239bc1de4279e2dd61 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 25 May 2021 22:29:01 +0100 Subject: [PATCH] Add HTTP keep-alive support Signed-off-by: Graham --- .../crossdomain/CrossDomainChannelHandler.kt | 17 ++++++++++ .../kotlin/org/openrs2/game/net/http/Http.kt | 32 ++++++++++++++++--- .../game/net/http/HttpChannelHandler.kt | 17 ++++++++++ .../game/net/http/HttpChannelInitializer.kt | 3 ++ .../game/net/login/LoginChannelHandler.kt | 3 ++ 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/game/src/main/kotlin/org/openrs2/game/net/crossdomain/CrossDomainChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/crossdomain/CrossDomainChannelHandler.kt index ecc137c4..da3a905c 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/crossdomain/CrossDomainChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/crossdomain/CrossDomainChannelHandler.kt @@ -7,6 +7,7 @@ import io.netty.channel.SimpleChannelInboundHandler import io.netty.handler.codec.http.HttpMethod import io.netty.handler.codec.http.HttpRequest import io.netty.handler.codec.http.HttpResponseStatus +import io.netty.handler.timeout.IdleStateEvent import org.openrs2.buffer.use import org.openrs2.game.net.http.Http @@ -39,5 +40,21 @@ public object CrossDomainChannelHandler : SimpleChannelInboundHandler() { override fun initChannel(ch: Channel) { ch.pipeline().addLast( + IdleStateHandler(true, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, TimeUnit.SECONDS), HttpRequestDecoder(), HttpResponseEncoder(), HttpObjectAggregator(Http.MAX_CONTENT_LENGTH), diff --git a/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt index f6acb2f6..02684107 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt @@ -9,6 +9,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator import io.netty.handler.codec.http.HttpRequestDecoder import io.netty.handler.codec.http.HttpResponseEncoder import io.netty.handler.codec.string.StringDecoder +import io.netty.handler.timeout.IdleStateHandler import org.openrs2.buffer.copiedBuffer import org.openrs2.game.net.crossdomain.CrossDomainChannelHandler import org.openrs2.game.net.http.Http @@ -22,6 +23,7 @@ import org.openrs2.protocol.js5.Js5ResponseEncoder import org.openrs2.protocol.js5.XorDecoder import org.openrs2.protocol.login.LoginRequest import org.openrs2.protocol.login.LoginResponse +import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Provider @@ -75,6 +77,7 @@ public class LoginChannelHandler @Inject constructor( private fun handleInitCrossDomainConnection(ctx: ChannelHandlerContext) { ctx.pipeline().addLast( + IdleStateHandler(true, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, TimeUnit.SECONDS), HttpRequestDecoder(), HttpResponseEncoder(), HttpObjectAggregator(Http.MAX_CONTENT_LENGTH),