Implementation
@override
Uint8List get bytes {
if (_headerBytes == null) {
final firstLine = [
'HTTP/$_httpVersion',
'$statusCode',
if (_statusReason != null && _statusReason!.isNotEmpty) _statusReason!,
].join(' ');
final text = [
firstLine,
..._header!.entries.map((e) => '${e.key}: ${e.value}'),
'',
'',
].join('\r\n');
_headerBytes = Uint8List.fromList(utf8.encode(text));
}
if (_bytes == null) {
final bb = BytesBuilder(copy: false);
bb.add(_headerBytes!);
bb.add(_payloadBytes!);
_bytes = bb.takeBytes();
}
return _bytes!;
}