Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.hexagonkt.http.handlers.HandlerBuilder.kt Maven / Gradle / Ivy
package com.hexagonkt.http.handlers
import com.hexagonkt.http.model.HttpMethod
import com.hexagonkt.http.model.HttpStatus
import kotlin.reflect.KClass
class HandlerBuilder(var handlers: List = emptyList()) {
fun handler(contextPath: String = ""): HttpHandler =
if (handlers.size == 1) handlers[0].addPrefix(contextPath)
else PathHandler(contextPath, handlers)
fun use(handler: HttpHandler) {
this.handlers += handler
}
fun path(pattern: String, block: HandlerBuilder.() -> Unit) {
use(com.hexagonkt.http.handlers.path(pattern, block))
}
fun path(pattern: String, pathHandler: PathHandler) {
use(pathHandler.addPrefix(pattern))
}
fun path(pattern: String, pathHandlers: List) {
use(PathHandler(pattern, pathHandlers))
}
fun path(pattern: String, vararg pathHandlers: HttpHandler) {
path(pattern, pathHandlers.toList())
}
fun on(
predicate: HttpPredicate = HttpPredicate(),
callback: HttpCallbackType
) {
use(OnHandler(predicate, callback))
}
fun on(
methods: Set = emptySet(),
pattern: String = "",
exception: KClass? = null,
status: HttpStatus? = null,
callback: HttpCallbackType,
) {
use(OnHandler(methods, pattern, exception, status, callback))
}
fun on(method: HttpMethod, pattern: String = "", callback: HttpCallbackType) {
use(OnHandler(method, pattern, callback))
}
fun on(pattern: String, callback: HttpCallbackType) {
use(OnHandler(pattern, callback))
}
fun filter(
predicate: HttpPredicate = HttpPredicate(),
callback: HttpCallbackType
) {
use(FilterHandler(predicate, callback))
}
fun filter(
methods: Set = emptySet(),
pattern: String = "",
exception: KClass? = null,
status: HttpStatus? = null,
callback: HttpCallbackType,
) {
use(
FilterHandler(methods, pattern, exception, status, callback)
)
}
fun filter(method: HttpMethod, pattern: String = "", callback: HttpCallbackType) {
use(FilterHandler(method, pattern, callback))
}
fun filter(pattern: String, callback: HttpCallbackType) {
use(FilterHandler(pattern, callback))
}
fun after(
predicate: HttpPredicate = HttpPredicate(),
callback: HttpCallbackType
) {
use(AfterHandler(predicate, callback))
}
fun after(
methods: Set = emptySet(),
pattern: String = "",
exception: KClass? = null,
status: HttpStatus? = null,
callback: HttpCallbackType,
) {
use(AfterHandler(methods, pattern, exception, status, callback))
}
fun after(method: HttpMethod, pattern: String = "", callback: HttpCallbackType) {
use(AfterHandler(method, pattern, callback))
}
fun after(pattern: String, callback: HttpCallbackType) {
use(AfterHandler(pattern, callback))
}
fun before(
predicate: HttpPredicate = HttpPredicate(),
callback: HttpCallbackType
) {
use(BeforeHandler(predicate, callback))
}
fun before(
methods: Set = emptySet(),
pattern: String = "",
exception: KClass? = null,
status: HttpStatus? = null,
callback: HttpCallbackType,
) {
use(BeforeHandler(methods, pattern, exception, status, callback))
}
fun before(method: HttpMethod, pattern: String = "", callback: HttpCallbackType) {
use(BeforeHandler(method, pattern, callback))
}
fun before(pattern: String, callback: HttpCallbackType) {
use(BeforeHandler(pattern, callback))
}
fun exception(
exception: KClass, clear: Boolean = true, callback: HttpExceptionCallbackType
) {
use(ExceptionHandler(exception, clear, callback))
}
inline fun exception(
clear: Boolean = true, noinline callback: HttpExceptionCallbackType,
) {
use(ExceptionHandler(T::class, clear, callback))
}
fun get(pattern: String = "", callback: HttpCallbackType) {
use(Get(pattern, callback))
}
fun ws(pattern: String = "", callback: HttpCallbackType) {
use(Ws(pattern, callback))
}
fun head(pattern: String = "", callback: HttpCallbackType) {
use(Head(pattern, callback))
}
fun post(pattern: String = "", callback: HttpCallbackType) {
use(Post(pattern, callback))
}
fun put(pattern: String = "", callback: HttpCallbackType) {
use(Put(pattern, callback))
}
fun delete(pattern: String = "", callback: HttpCallbackType) {
use(Delete(pattern, callback))
}
fun trace(pattern: String = "", callback: HttpCallbackType) {
use(Trace(pattern, callback))
}
fun options(pattern: String = "", callback: HttpCallbackType) {
use(Options(pattern, callback))
}
fun patch(pattern: String = "", callback: HttpCallbackType) {
use(Patch(pattern, callback))
}
}