http4k Kotlin
http4k માટે Kotlin સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty GIF થી આપે છે. GIF સ્ટાર્ટઅપ વખતે એક જ વાર ડિકોડ થાય છે.
http4k Kotlin
import org.http4k.core.Method.GET
import org.http4k.core.MemoryBody
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.routing.bind
import org.http4k.routing.routes
import org.http4k.server.SunHttp
import org.http4k.server.asServer
import java.util.Base64
private val GIF = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
val app = routes(
"/pixel.gif" bind GET to {
Response(OK)
.header("Content-Type", "image/gif")
.header("Cache-Control", "no-store")
.body(MemoryBody(GIF))
},
)
fun main() {
app.asServer(SunHttp(8080)).start()
}
અમે આ સ્નિપેટ ચલાવ્યો અને તેણે પરત કરેલા બાઇટની સરખામણી કરી.
ચકાસો
curl -sI http://localhost:8080/pixel.gif