HttpBody.fromBytes constructor

HttpBody.fromBytes(
  1. MediaType? contentType,
  2. List<int>? bytes, {
  3. Encoding? encoding,
  4. Encoding? fallbackEncoding,
})

Construct the body to an HTTP request or an HTTP response from bytes.

If encoding is given, it will be used to encode/decode the body.

Otherwise, the charset parameter from contentType will be mapped to an Encoding supported by Dart.

If a charset parameter is not available or the value is unrecognized, fallbackEncoding will be used.

If fallbackEncoding is null, utf-8 will be the default encoding.

If an encoding cannot be parsed from the content-type header (via the charset param), then fallbackEncoding will be used (utf-8 by default).

Implementation

HttpBody.fromBytes(this.contentType, List<int>? bytes,
    {Encoding? encoding, Encoding? fallbackEncoding})
    : _encoding =
          encoding ?? http_utils.parseEncodingFromContentType(contentType),
      _fallbackEncoding = fallbackEncoding ?? utf8,
      _bytes = Uint8List.fromList(bytes ?? []);