Dart standard library (dart:io) Dart
Dart standard library (dart:io) માટે Dart સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty 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)