-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from hexagonkt/develop
Minor Netty optimizations
- Loading branch information
Showing
10 changed files
with
163 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...tp_server_netty/src/main/kotlin/com/hexagonkt/http/server/netty/HttpChannelInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.hexagonkt.http.server.netty | ||
|
||
import com.hexagonkt.http.handlers.HttpHandler | ||
import com.hexagonkt.http.server.HttpServerSettings | ||
import io.netty.channel.ChannelInitializer | ||
import io.netty.channel.socket.SocketChannel | ||
import io.netty.handler.codec.http.* | ||
import io.netty.handler.stream.ChunkedWriteHandler | ||
import io.netty.util.concurrent.EventExecutorGroup | ||
|
||
internal class HttpChannelInitializer( | ||
private val handlers: Map<HttpMethod, HttpHandler>, | ||
private val executorGroup: EventExecutorGroup?, | ||
private val settings: HttpServerSettings, | ||
private val keepAliveHandler: Boolean = true, | ||
private val httpAggregatorHandler: Boolean = true, | ||
private val chunkedHandler: Boolean = true, | ||
private val enableWebsockets: Boolean = true, | ||
) : ChannelInitializer<SocketChannel>() { | ||
|
||
override fun initChannel(channel: SocketChannel) { | ||
val pipeline = channel.pipeline() | ||
|
||
pipeline.addLast(HttpServerCodec()) | ||
|
||
if (keepAliveHandler) | ||
pipeline.addLast(HttpServerKeepAliveHandler()) | ||
if (httpAggregatorHandler) | ||
pipeline.addLast(HttpObjectAggregator(Int.MAX_VALUE)) | ||
if (chunkedHandler) | ||
pipeline.addLast(ChunkedWriteHandler()) | ||
if (settings.zip) | ||
pipeline.addLast(HttpContentCompressor()) | ||
|
||
val nettyServerHandler = NettyServerHandler(handlers, null, enableWebsockets) | ||
|
||
if (executorGroup == null) | ||
pipeline.addLast(nettyServerHandler) | ||
else | ||
pipeline.addLast(executorGroup, nettyServerHandler) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...p_server_netty/src/main/kotlin/com/hexagonkt/http/server/netty/HttpsChannelInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.hexagonkt.http.server.netty | ||
|
||
import com.hexagonkt.http.SslSettings | ||
import com.hexagonkt.http.handlers.HttpHandler | ||
import com.hexagonkt.http.server.HttpServerSettings | ||
import io.netty.channel.ChannelInitializer | ||
import io.netty.channel.socket.SocketChannel | ||
import io.netty.handler.codec.http.* | ||
import io.netty.handler.ssl.SslContext | ||
import io.netty.handler.stream.ChunkedWriteHandler | ||
import io.netty.util.concurrent.EventExecutorGroup | ||
|
||
internal class HttpsChannelInitializer( | ||
private val handlers: Map<HttpMethod, HttpHandler>, | ||
private val sslContext: SslContext, | ||
private val sslSettings: SslSettings, | ||
private val executorGroup: EventExecutorGroup?, | ||
private val settings: HttpServerSettings, | ||
private val keepAliveHandler: Boolean = true, | ||
private val httpAggregatorHandler: Boolean = true, | ||
private val chunkedHandler: Boolean = true, | ||
private val enableWebsockets: Boolean = true, | ||
) : ChannelInitializer<SocketChannel>() { | ||
|
||
override fun initChannel(channel: SocketChannel) { | ||
val pipeline = channel.pipeline() | ||
val sslHandler = sslContext.newHandler(channel.alloc()) | ||
val handlerSsl = if (sslSettings.clientAuth) sslHandler else null | ||
|
||
pipeline.addLast(sslHandler) | ||
pipeline.addLast(HttpServerCodec()) | ||
|
||
if (keepAliveHandler) | ||
pipeline.addLast(HttpServerKeepAliveHandler()) | ||
if (httpAggregatorHandler) | ||
pipeline.addLast(HttpObjectAggregator(Int.MAX_VALUE)) | ||
if (chunkedHandler) | ||
pipeline.addLast(ChunkedWriteHandler()) | ||
if (settings.zip) | ||
pipeline.addLast(HttpContentCompressor()) | ||
|
||
val serverHandler = NettyServerHandler(handlers, handlerSsl, enableWebsockets) | ||
|
||
if (executorGroup == null) | ||
pipeline.addLast(serverHandler) | ||
else | ||
pipeline.addLast(executorGroup, serverHandler) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.