ServerResponse.bytes constructor

ServerResponse.bytes(
  1. List<int> bytes, {
  2. int status = 200,
  3. String? contentType,
  4. Headers? headers,
})

Creates a response from buffered bytes.

Implementation

factory ServerResponse.bytes(
  List<int> bytes, {
  int status = 200,
  String? contentType,
  Headers? headers,
}) {
  final resolved = headers?.copy() ?? Headers();
  if (contentType != null) resolved.set('content-type', contentType);
  resolved.set('content-length', '${bytes.length}');
  return ServerResponse(
    status: status,
    headers: resolved,
    body: Stream<List<int>>.value(bytes),
  );
}