ServerResponse.okHtml constructor

ServerResponse.okHtml(
  1. String html, {
  2. Map<String, String>? headers,
  3. String? etag,
  4. DateTime? lastModified,
  5. String? cacheControl,
})

Creates a successful 200 OK HTML response.

Implementation

factory ServerResponse.okHtml(
  String html, {
  Map<String, String>? headers,
  String? etag,
  DateTime? lastModified,
  String? cacheControl,
}) {
  final responseHeaders = <String, String>{
    'Content-Type': 'text/html; charset=utf-8',
    'Vary': 'Accept-Encoding',
    'X-Content-Type-Options': 'nosniff',
    if (headers != null) ...headers,
    if (etag != null) 'ETag': etag,
    if (lastModified != null)
      'Last-Modified': lastModified.toUtc().toIso8601String(),
    if (cacheControl != null) 'Cache-Control': cacheControl,
  };

  return ServerResponse(
    statusCode: 200,
    headers: responseHeaders,
    body: html,
  );
}