அனைத்து மொழிகளும் ஃப்ரேம்வொர்க்குகளும்
Vapor Swift
/pixel.gif க்கு வரும் ரெக்வெஸ்ட்களுக்கு empty GIF மூலம் பதிலளிக்கும், Vapor க்கான Swift ஸ்னிப்பெட். 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