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