mirror of
https://github.com/revanced/revanced-api.git
synced 2025-04-29 22:24:31 +02:00
fix: Add uri to rate limiter request key
This commit is contained in:
parent
a6008a2fb6
commit
e8c2488bc6
@ -5,6 +5,7 @@ import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.plugins.ratelimit.*
|
||||
import io.ktor.server.request.*
|
||||
import org.koin.ktor.ext.get
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
@ -19,13 +20,19 @@ fun Application.configureHTTP() {
|
||||
}
|
||||
|
||||
install(RateLimit) {
|
||||
register(RateLimitName("weak")) {
|
||||
rateLimiter(limit = 30, refillPeriod = 2.minutes)
|
||||
requestKey { it.request.origin.remoteAddress }
|
||||
fun rateLimit(name: String, block: RateLimitProviderConfig.() -> Unit) = register(RateLimitName(name)) {
|
||||
requestKey {
|
||||
it.request.uri + it.request.origin.remoteAddress
|
||||
}
|
||||
|
||||
block()
|
||||
}
|
||||
register(RateLimitName("strong")) {
|
||||
|
||||
rateLimit("weak") {
|
||||
rateLimiter(limit = 30, refillPeriod = 2.minutes)
|
||||
}
|
||||
rateLimit("strong") {
|
||||
rateLimiter(limit = 5, refillPeriod = 1.minutes)
|
||||
requestKey { it.request.origin.remoteHost }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user