Vapor Swift
Vapor ਲਈ Swift ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ GIF ਨਾਲ ਦਿੰਦਾ ਹੈ; GIF ਸ਼ੁਰੂਆਤ ’ਤੇ ਇੱਕ ਵਾਰ ਡੀਕੋਡ ਹੁੰਦੀ ਹੈ।
Vapor Swift
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