emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Vapor Swift

Ein Swift-Snippet für Vapor, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Vapor Swift

Installieren
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0")
Datei
Server.swift
Ausführen
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()
    }
}

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Vapor

Mehr in Swift