emptygif
언어: 한국어

모든 언어 및 프레임워크

Vapor Swift

/pixel.gif 요청에 빈 GIF로 응답하는 Vapor용 Swift 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

Vapor Swift

설치
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0")
파일
Server.swift
실행
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()
    }
}

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: Vapor

Swift의 다른 예제