mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-12 21:00:35 +08:00
更新 RoutedHttpHandler 功能
This commit is contained in:
parent
b05a554459
commit
76fce89ca0
@ -48,15 +48,15 @@ open class RoutedHttpHandler<T : HttpContent, in E : ExceptionContent>(
|
||||
}
|
||||
|
||||
fun addRouter(route: String, handler: (T) -> Unit) {
|
||||
router[route] = handler
|
||||
router[safeRoute(route)] = handler
|
||||
}
|
||||
|
||||
fun addRouter(method: String, route: String, handler: (T) -> Unit) {
|
||||
getRouter(method)[route] = handler
|
||||
getRouter(method)[safeRoute(route)] = handler
|
||||
}
|
||||
|
||||
fun deleteRouter(route: String, method: String) {
|
||||
getRouter(method).delRoute(route)
|
||||
getRouter(method).delRoute(safeRoute(route))
|
||||
}
|
||||
|
||||
private fun insertMapping(method: Method) {
|
||||
@ -108,7 +108,7 @@ open class RoutedHttpHandler<T : HttpContent, in E : ExceptionContent>(
|
||||
}
|
||||
routes.forEach { route ->
|
||||
log?.info("method {} mapped to route {}", method, route)
|
||||
router[route] = { content -> method(this, content) }
|
||||
router[safeRoute(route)] = { content -> method(this, content) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,5 +132,7 @@ open class RoutedHttpHandler<T : HttpContent, in E : ExceptionContent>(
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
private fun safeRoute(route: String) = if (route.first() == '/') route else "/$route"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user