Dart standard library (dart:io) Dart
Ein Dart-Snippet für Dart standard library (dart:io), das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.
Dart standard library (dart:io) Dart
import 'dart:convert';
import 'dart:io';
final gif = base64Decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
Future<void> main() async {
final server = await HttpServer.bind(InternetAddress.anyIPv4, 8080);
await for (final request in server) {
final response = request.response;
if (request.method == 'GET' && request.uri.path == '/pixel.gif') {
response.headers
..contentType = ContentType('image', 'gif')
..set(HttpHeaders.cacheControlHeader, 'no-store');
response.contentLength = gif.length;
response.add(gif);
} else {
response.statusCode = HttpStatus.notFound;
}
await response.close();
}
}
Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.
Prüfen
curl -sI http://localhost:8080/pixel.gif
Offizielle Website: Dart standard library (dart:io)