mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-13 21:31:25 +08:00
细化功能
This commit is contained in:
parent
702d8a44f3
commit
d9b7b3a5d4
@ -24,7 +24,7 @@ class NettyHttpHandler(
|
|||||||
|
|
||||||
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
|
override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {
|
||||||
val content = NettyExceptionContent(ctx, cause)
|
val content = NettyExceptionContent(ctx, cause)
|
||||||
handler.exception(content)
|
handler.exceptionCause(content)
|
||||||
if (!content.finished) {
|
if (!content.finished) {
|
||||||
content.responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR
|
content.responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR
|
||||||
content.finish()
|
content.finish()
|
||||||
|
@ -3,7 +3,7 @@ package cn.tursom.web
|
|||||||
interface HttpHandler<in T : HttpContent, in E : ExceptionContent> {
|
interface HttpHandler<in T : HttpContent, in E : ExceptionContent> {
|
||||||
fun handle(content: T)
|
fun handle(content: T)
|
||||||
|
|
||||||
fun exception(e: E) {
|
fun exceptionCause(e: E) {
|
||||||
e.cause.printStackTrace()
|
e.cause.printStackTrace()
|
||||||
e.responseCode = 500
|
e.responseCode = 500
|
||||||
e.finish()
|
e.finish()
|
||||||
|
@ -20,7 +20,6 @@ open class RoutedHttpHandler<T : HttpContent, in E : ExceptionContent>(
|
|||||||
target: Any? = null,
|
target: Any? = null,
|
||||||
val routerMaker: () -> Router<(T) -> Unit> = { SimpleRouter() }
|
val routerMaker: () -> Router<(T) -> Unit> = { SimpleRouter() }
|
||||||
) : HttpHandler<T, E> {
|
) : HttpHandler<T, E> {
|
||||||
|
|
||||||
private val router: Router<(T) -> Unit> = routerMaker()
|
private val router: Router<(T) -> Unit> = routerMaker()
|
||||||
private val routerMap: HashMap<String, Router<(T) -> Unit>> = HashMap()
|
private val routerMap: HashMap<String, Router<(T) -> Unit>> = HashMap()
|
||||||
|
|
||||||
@ -35,10 +34,14 @@ open class RoutedHttpHandler<T : HttpContent, in E : ExceptionContent>(
|
|||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler(content)
|
handler(content)
|
||||||
} else {
|
} else {
|
||||||
content.finish(404)
|
notFound(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun notFound(content: T) {
|
||||||
|
content.finish(404)
|
||||||
|
}
|
||||||
|
|
||||||
fun addRouter(handler: Any) {
|
fun addRouter(handler: Any) {
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
val clazz = handler.javaClass
|
val clazz = handler.javaClass
|
||||||
|
@ -3,9 +3,28 @@ package cn.tursom.web.utils
|
|||||||
import cn.tursom.core.buffer.ByteBuffer
|
import cn.tursom.core.buffer.ByteBuffer
|
||||||
|
|
||||||
interface Chunked {
|
interface Chunked {
|
||||||
|
/**
|
||||||
|
* Returns current transfer progress.
|
||||||
|
*/
|
||||||
val progress: Long
|
val progress: Long
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of the input.
|
||||||
|
* @return the length of the input if the length of the input is known.
|
||||||
|
* a negative value if the length of the input is unknown.
|
||||||
|
*/
|
||||||
val length: Long
|
val length: Long
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return {@code true} if and only if there is no data left in the stream
|
||||||
|
* and the stream has reached at its end.
|
||||||
|
*/
|
||||||
val endOfInput: Boolean
|
val endOfInput: Boolean
|
||||||
|
|
||||||
fun readChunk(): ByteBuffer
|
fun readChunk(): ByteBuffer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the resources associated with the input.
|
||||||
|
*/
|
||||||
fun close()
|
fun close()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user