MockStreamedResponse constructor

MockStreamedResponse(
  1. int status, {
  2. Stream<List<int>>? byteStream,
  3. Encoding? encoding,
  4. Map<String, String>? headers,
  5. String? statusText,
})

Implementation

MockStreamedResponse(int status,
    {Stream<List<int>>? byteStream,
    Encoding? encoding,
    Map<String, String>? headers,
    String? statusText}) {
  // Ensure the headers are case insensitive.
  headers = CaseInsensitiveMap<String>.from(headers ?? {});

  // If an encoding was given, update the content-type charset parameter.
  if (encoding != null) {
    MediaType contentType = http_utils.parseContentTypeFromHeaders(headers);
    contentType = contentType.change(parameters: {'charset': encoding.name});
    headers['content-type'] = contentType.toString();
  }

  // Use a default status text based on the status code if one is not given.
  statusText ??= _mapStatusToText(status);
  byteStream ??= Stream.fromIterable([]);

  // Construct the body according to the data type.
  _response = StreamedResponse.fromByteStream(
      status, statusText, headers, byteStream);
}