Created
June 19, 2020 09:58
-
-
Save e5l/31bcf22a813008bd7418b5c944b225c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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