emptygif
Idioma: Español

Todos los lenguajes y frameworks

Shelf Dart

Un fragmento en Dart para Shelf que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Shelf Dart

Instalar
dart pub add shelf shelf_router
Archivo
server.dart
Ejecutar
dart run bin/server.dart
import 'dart:convert';
import 'dart:io';

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_router/shelf_router.dart';

final gif = base64Decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

Future<void> main() async {
  final router = Router()
    ..get('/pixel.gif', (Request request) {
      return Response.ok(gif, headers: {
        HttpHeaders.contentTypeHeader: 'image/gif',
        HttpHeaders.cacheControlHeader: 'no-store',
      });
    });

  await io.serve(router.call, InternetAddress.anyIPv4, 8080);
}

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

curl -sI http://localhost:8080/pixel.gif

Sitio oficial: Shelf

Más en Dart