All Downloads are FREE. Search and download functionalities are using the official Maven repository.

utility.EncryptionEnforcementFeature.kt Maven / Gradle / Ivy

There is a newer version: 0.9.27
Show newest version
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."
				)
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy