emptygif
Wika: Filipino

Lahat ng language at framework

Vapor Swift

Isang Swift snippet para sa Vapor na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Vapor Swift

I-install
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0")
File
Server.swift
Patakbuhin
swift run
import Foundation
import Vapor

let gif = Data(base64Encoded: "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")!

@main
struct Server {
    static func main() async throws {
        let app = try await Application.make(.detect())
        app.http.server.configuration.port = 8080

        app.get("/pixel.gif".pathComponents) { _ in
            Response(
                status: .ok,
                headers: ["Content-Type": "image/gif", "Cache-Control": "no-store"],
                body: .init(data: gif)
            )
        }

        try await app.execute()
        try await app.asyncShutdown()
    }
}

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Vapor

Iba pa sa Swift