emptygif
語言: 繁體中文

所有語言和框架

Pode PowerShell

適用於 Pode 的 PowerShell 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,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 範例