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# 示例