From e41da3463a849cdc0e310d301f7c3d037381e878 Mon Sep 17 00:00:00 2001 From: tursom Date: Sat, 14 Dec 2019 23:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ByteBuffer.finishWrite=20?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt | 2 +- .../kotlin/cn/tursom/web/netty/NettyHttpContent.kt | 2 ++ .../kotlin/cn/tursom/web/router/RoutedHttpHandler.kt | 12 +++++------- .../cn/tursom/web/router/AsyncRoutedHttpHandler.kt | 5 ++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt b/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt index d09cadf..b167a93 100644 --- a/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt +++ b/src/main/kotlin/cn/tursom/core/buffer/ByteBuffer.kt @@ -60,7 +60,7 @@ interface ByteBuffer : Closeable { fun writeBuffer(): java.nio.ByteBuffer fun finishWrite(buffer: java.nio.ByteBuffer) { - readPosition = buffer.position() + writePosition = buffer.position() } fun reset() diff --git a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt b/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt index e941ffc..09934ab 100644 --- a/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt +++ b/web/netty-web/src/main/kotlin/cn/tursom/web/netty/NettyHttpContent.kt @@ -161,12 +161,14 @@ open class NettyHttpContent( } override fun finishChunked() { + writeChunkedHeader() finished = true val httpChunkWriter = HttpChunkedInput(NettyChunkedByteBuffer(chunkedList)) ctx.writeAndFlush(httpChunkWriter) } override fun finishChunked(chunked: Chunked) { + writeChunkedHeader() finished = true val httpChunkWriter = HttpChunkedInput(NettyChunkedInput(chunked)) ctx.writeAndFlush(httpChunkWriter) diff --git a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt b/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt index e408832..7bad839 100644 --- a/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt +++ b/web/src/main/kotlin/cn/tursom/web/router/RoutedHttpHandler.kt @@ -7,17 +7,16 @@ import cn.tursom.web.ExceptionContent import cn.tursom.web.HttpContent import cn.tursom.web.HttpHandler import cn.tursom.web.MutableHttpContent -import cn.tursom.web.router.impl.SimpleRouter import cn.tursom.web.mapping.* import cn.tursom.web.result.Html import cn.tursom.web.result.Json import cn.tursom.web.result.Text +import cn.tursom.web.router.impl.SimpleRouter import cn.tursom.web.utils.Chunked import org.slf4j.LoggerFactory import java.io.File import java.io.RandomAccessFile import java.lang.reflect.Method -import kotlin.reflect.KCallable /** * 自动添加路径映射的处理器 @@ -66,7 +65,7 @@ open class RoutedHttpHandler( return@forEach } } - log?.debug("mapping {} {}", method, method.parameterTypes) + log?.trace("mapping {} {}", method, method.parameterTypes) insertMapping(handler, method) } } @@ -101,9 +100,8 @@ open class RoutedHttpHandler( protected fun insertMapping(obj: Any, method: Method) { val mapping = obj::class.java.getAnnotation(Mapping::class.java)?.route ?: arrayOf("") method.annotations.forEach { annotation -> - log?.info("method route {} annotation {}", method, annotation) val (routes, router) = getRoutes(annotation) ?: return@forEach - log?.info("method route {} mapped to {}", method, routes) + log?.info("mapping {} => {}", routes, method) routes.forEach { route -> if (mapping.isEmpty()) { addRouter(obj, method, route, router) @@ -159,12 +157,12 @@ open class RoutedHttpHandler( @Suppress("LeakingThis") val clazz = handler.javaClass clazz.methods.forEach { method -> - log?.debug("try mapping {}", method) method.parameterTypes.let { if (!(it.size == 1 && HttpContent::class.java.isAssignableFrom(it[0])) && it.isNotEmpty()) { return@forEach } } + log?.debug("delete mapping {}", method) deleteMapping(handler, method) } } @@ -174,7 +172,7 @@ open class RoutedHttpHandler( method.annotations.forEach { annotation -> val (routes, router) = getRoutes(annotation) ?: return@forEach routes.forEach { route -> - log?.info("delete route {} mapped to {}", route, method) + log?.info("delete route {} => {}", route, method) if (mapping.isEmpty()) { deleteMapping(obj, route, router) } else mapping.forEach { diff --git a/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt b/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt index 4574172..332c01c 100644 --- a/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt +++ b/web/web-coroutine/src/main/kotlin/cn/tursom/web/router/AsyncRoutedHttpHandler.kt @@ -75,7 +75,7 @@ open class AsyncRoutedHttpHandler( return@forEach } } - log?.debug("mapping {} {}", member, member.parameters) + log?.trace("mapping {} {}", member, member.parameters) insertMapping(handler, member) } } @@ -84,10 +84,9 @@ open class AsyncRoutedHttpHandler( protected fun insertMapping(obj: Any, method: KCallable<*>) { val mapping = obj::class.java.getAnnotation(Mapping::class.java)?.route ?: arrayOf("") method.annotations.forEach { annotation -> - log?.info("method route {} annotation {}", method, annotation) val (routes, router) = getAsyncRoutes(annotation) ?: return@forEach @Suppress("DuplicatedCode") - log?.info("method route {} mapped to {}", method, routes) + log?.info("mapping {} => {}", routes, method) routes.forEach { route -> if (mapping.isEmpty()) { addRouter(obj, method, route, router)