emptygif
語言: 繁體中文

所有語言和框架

Giraffe F#

適用於 Giraffe 的 F# 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Giraffe F#

安裝
dotnet add package Giraffe
檔案
Program.fs
執行
dotnet run
open System
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Giraffe

let gif = Convert.FromBase64String "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="

let pixel: HttpHandler =
    setHttpHeader "Content-Type" "image/gif"
    >=> setHttpHeader "Cache-Control" "no-store"
    >=> setBody gif

let webApp =
    choose [
        GET >=> route "/pixel.gif" >=> pixel
        RequestErrors.NOT_FOUND "Not Found"
    ]

let builder = WebApplication.CreateBuilder()
builder.Services.AddGiraffe() |> ignore

let app = builder.Build()
app.UseGiraffe webApp
app.Run "http://0.0.0.0:8080"

我們執行了這段程式碼,並比對了它回傳的位元組。

驗證

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

官方網站: Giraffe

更多 F# 範例