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

View File

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

View File

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