xDnsPrefetchControl function

Middleware xDnsPrefetchControl({
  1. bool allow = false,
})

This middleware lets you set the X-DNS-Prefetch-Control to control browsers' DNS prefetching. Read more about it on MDN and on Chromium's docs.

Usage:

import 'package:shelf_helmet/shelf_helmet.dart'

//Set X-DNS-Prefetch-Control: off
.addMiddleware(xDownloadOptions())

//Set X-DNS-Prefetch-Control: on
.addMiddleware(xDownloadOptions(allow: true))

Implementation

Middleware xDnsPrefetchControl({bool allow = false}) {
  return (innerHandler) {
    return (request) async {
      final response = await innerHandler(request);
      return response.change(
        headers: {
          'x-dns-prefetch-control': allow ? 'on' : 'off',
          ...response.headersAll,
        },
      );
    };
  };
}