Spring WebFlux (Kotlin coRouter) Kotlin
Spring WebFlux (Kotlin coRouter) साठी Kotlin स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.
Spring WebFlux (Kotlin coRouter) Kotlin
package com.example.pixel
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.http.CacheControl
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.bodyValueAndAwait
import org.springframework.web.reactive.function.server.coRouter
import java.util.Base64
private val GIF: ByteArray = Base64.getDecoder().decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
@SpringBootApplication
class PixelApplication {
@Bean
fun pixelRoutes() = coRouter {
GET("/pixel.gif") {
ok().contentType(MediaType.IMAGE_GIF)
.contentLength(GIF.size.toLong())
.cacheControl(CacheControl.noStore())
.bodyValueAndAwait(GIF)
}
}
}
fun main(args: Array<String>) {
runApplication<PixelApplication>(*args)
}
आम्ही हा स्निपेट चालवला आणि त्याने परत केलेले बाइट्स तुलना करून पाहिले.
तपासा
curl -sI http://localhost:8080/pixel.gif
अधिकृत साइट: Spring WebFlux (Kotlin coRouter)