Dart Frog Dart
適用於 Dart Frog 的 Dart 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Dart Frog Dart
// routes/pixel.gif.dart: the file name is the route.
import 'dart:convert';
import 'package:dart_frog/dart_frog.dart';
final _gif = base64Decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
Response onRequest(RequestContext context) {
return Response.bytes(
body: _gif,
headers: {'content-type': 'image/gif', 'cache-control': 'no-store'},
);
}
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif