emptygif
言語: 日本語

すべての言語・フレームワーク

Pode PowerShell

/pixel.gif へのリクエストに空の GIF を返す、Pode 用の PowerShell スニペット。GIF は起動時に一度だけデコードします。

Pode PowerShell

インストール
Install-Module -Name Pode
ファイル
server.ps1
実行
pwsh ./server.ps1
Import-Module Pode

Start-PodeServer {
    Add-PodeEndpoint -Address * -Port 8080 -Protocol Http
    Set-PodeState -Name 'Gif' -Value ([Convert]::FromBase64String('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')) | Out-Null

    Add-PodeRoute -Method Get -Path '/pixel.gif' -ScriptBlock {
        Set-PodeHeader -Name 'Cache-Control' -Value 'no-store'
        # Pode appends '; charset=utf-8' to the type; browsers ignore it for images.
        Write-PodeTextResponse -Bytes (Get-PodeState -Name 'Gif') -ContentType 'image/gif'
    }
}

このスニペットは実行し、返されたバイト列を照合しました。

確認

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

公式サイト: Pode

PowerShell の他の例