Dart standard library (dart:io) Dart
Dart standard library (dart:io) ਲਈ Dart ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ GIF ਨਾਲ ਦਿੰਦਾ ਹੈ; GIF ਸ਼ੁਰੂਆਤ ’ਤੇ ਇੱਕ ਵਾਰ ਡੀਕੋਡ ਹੁੰਦੀ ਹੈ।
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();
}
}
ਅਸੀਂ ਇਹ ਸਨਿੱਪਟ ਚਲਾਇਆ ਅਤੇ ਇਸ ਵੱਲੋਂ ਵਾਪਸ ਕੀਤੀਆਂ ਬਾਈਟਾਂ ਦੀ ਤੁਲਨਾ ਕੀਤੀ।
ਜਾਂਚੋ
curl -sI http://localhost:8080/pixel.gif
ਅਧਿਕਾਰਤ ਸਾਈਟ: Dart standard library (dart:io)