emptygif
Harshe: Hausa

Duk harsuna da frameworks

Ktor Kotlin

Snippet na Kotlin don Ktor da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

Ktor Kotlin

Girkawa
implementation("io.ktor:ktor-server-netty:3.6.0")
Fayil
Application.kt
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.response.header
import io.ktor.server.response.respondBytes
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import kotlin.io.encoding.Base64

private val GIF = Base64.decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

fun main() {
    embeddedServer(Netty, port = 8080) {
        routing {
            get("/pixel.gif") {
                call.response.header(HttpHeaders.CacheControl, "no-store")
                call.respondBytes(GIF, ContentType.Image.GIF)
            }
        }
    }.start(wait = true)
}

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

curl -sI http://localhost:8080/pixel.gif

Shafin hukuma: Ktor

Ƙari a Kotlin