utility.EncryptionEnforcementFeature.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baku Show documentation
Show all versions of baku Show documentation
helps you focus your REST API back-end on the business logic
package com.github.fluidsonic.baku
import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.ApplicationFeature
import io.ktor.application.call
import io.ktor.features.origin
import io.ktor.util.AttributeKey
internal object EncryptionEnforcementFeature : ApplicationFeature {
override val key = AttributeKey("Baku: encryption enforcement feature")
override fun install(pipeline: ApplicationCallPipeline, configure: Unit.() -> Unit) {
Unit.configure()
pipeline.intercept(ApplicationCallPipeline.Features) {
if (call.request.origin.scheme != "https")
throw BakuCommandFailure(
code = "encryptedConnectionRequired",
userMessage = BakuCommandFailure.genericUserMessage,
developerMessage = "This API must only be used over an encrypted connection."
)
}
}
}