修复 NettyHttpContent 返回代码错误的 bug

This commit is contained in:
tursom 2019-11-28 17:39:32 +08:00
parent 5d891ad24b
commit d587e90024
4 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,5 @@
dependencies { dependencies {
implementation project(":") implementation project(":")
implementation project(":web") implementation project(":web")
implementation group: "io.netty", name: "netty-all", version: "4.1.33.Final" implementation group: "io.netty", name: "netty-all", version: "4.1.43.Final"
} }

View File

@ -18,6 +18,7 @@ open class NettyHttpContent(
val ctx: ChannelHandlerContext, val ctx: ChannelHandlerContext,
val msg: FullHttpRequest val msg: FullHttpRequest
) : AdvanceHttpContent, NettyResponseHeaderAdapter() { ) : AdvanceHttpContent, NettyResponseHeaderAdapter() {
override var finished: Boolean = false
override val uri: String by lazy { override val uri: String by lazy {
var uri = msg.uri() var uri = msg.uri()
while (uri.contains("//")) { while (uri.contains("//")) {
@ -127,6 +128,7 @@ open class NettyHttpContent(
} }
fun finish(response: FullHttpResponse) { fun finish(response: FullHttpResponse) {
finished = true
val heads = response.headers() val heads = response.headers()
addHeaders( addHeaders(
heads, heads,
@ -159,21 +161,25 @@ open class NettyHttpContent(
} }
override fun finishChunked() { override fun finishChunked() {
finished = true
val httpChunkWriter = HttpChunkedInput(NettyChunkedByteBuffer(chunkedList)) val httpChunkWriter = HttpChunkedInput(NettyChunkedByteBuffer(chunkedList))
ctx.writeAndFlush(httpChunkWriter) ctx.writeAndFlush(httpChunkWriter)
} }
override fun finishChunked(chunked: Chunked) { override fun finishChunked(chunked: Chunked) {
finished = true
val httpChunkWriter = HttpChunkedInput(NettyChunkedInput(chunked)) val httpChunkWriter = HttpChunkedInput(NettyChunkedInput(chunked))
ctx.writeAndFlush(httpChunkWriter) ctx.writeAndFlush(httpChunkWriter)
} }
override fun finishFile(file: File, chunkSize: Int) { override fun finishFile(file: File, chunkSize: Int) {
finished = true
writeChunkedHeader() writeChunkedHeader()
ctx.writeAndFlush(HttpChunkedInput(ChunkedFile(file, chunkSize))) ctx.writeAndFlush(HttpChunkedInput(ChunkedFile(file, chunkSize)))
} }
override fun finishFile(file: RandomAccessFile, offset: Long, length: Long, chunkSize: Int) { override fun finishFile(file: RandomAccessFile, offset: Long, length: Long, chunkSize: Int) {
finished = true
writeChunkedHeader() writeChunkedHeader()
ctx.writeAndFlush(HttpChunkedInput(ChunkedFile(file, offset, length, chunkSize))) ctx.writeAndFlush(HttpChunkedInput(ChunkedFile(file, offset, length, chunkSize)))
} }

View File

@ -8,6 +8,7 @@ import java.io.RandomAccessFile
import java.net.SocketAddress import java.net.SocketAddress
interface HttpContent : ResponseHeaderAdapter, RequestHeaderAdapter { interface HttpContent : ResponseHeaderAdapter, RequestHeaderAdapter {
val finished: Boolean
val uri: String val uri: String
var responseCode: Int var responseCode: Int
var responseMessage: String? var responseMessage: String?

View File

@ -9,6 +9,7 @@ import java.net.InetSocketAddress
import java.net.SocketAddress import java.net.SocketAddress
class EmptyHttpContent( class EmptyHttpContent(
override val finished: Boolean = true,
override val uri: String = "/", override val uri: String = "/",
override var responseCode: Int = 200, override var responseCode: Int = 200,
override var responseMessage: String? = null, override var responseMessage: String? = null,