1
0
Files
KotlinStarter/src/main/kotlin/starter/extensions/Http4kExtensions.kt
T
2020-09-30 02:39:58 +02:00

18 lines
576 B
Kotlin

@file:Suppress("NOTHING_TO_INLINE")
package starter.extensions
import org.http4k.core.Response
import org.http4k.core.Status
import starter.utils.sanitizeFilename
import java.io.InputStream
inline fun Response.Companion.ok() = Response(Status.OK)
inline fun Response.Companion.badRequest() = Response(Status.BAD_REQUEST)
fun attachment(value: InputStream, name: String, contentType: String) = { res: Response ->
res.header("Content-Type", contentType)
.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(name)}\"")
.body(value)
}