Skip to content

Instantly share code, notes, and snippets.

@e5l
Created June 19, 2020 09:58
Show Gist options
  • Save e5l/31bcf22a813008bd7418b5c944b225c9 to your computer and use it in GitHub Desktop.
Save e5l/31bcf22a813008bd7418b5c944b225c9 to your computer and use it in GitHub Desktop.
class Timeouts {
class Config(var postRequestTimeout: Long = 5000L)
companion object : ApplicationFeature<ApplicationCallPipeline, Config, Unit> {
override val key: AttributeKey<Unit> = AttributeKey("Timeouts")
override fun install(pipeline: ApplicationCallPipeline, configure: Config.() -> Unit) {
val postTimeout = Config().apply(configure).postRequestTimeout
if (postTimeout <= 0) return
pipeline.intercept(ApplicationCallPipeline.Features) {
if (call.request.httpMethod != HttpMethod.Post) return@intercept
withTimeout(postTimeout) {
proceed()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment