TransferEncodingHeader.encodings constructor
TransferEncodingHeader.encodings(
- List<
TransferEncoding> encodings
Constructs a TransferEncodingHeader instance with the specified transfer encodings.
Per RFC 9112 6.1 the chunked transfer-coding, if present, MUST be the
final coding. A list with chunked in any other position is rejected
rather than silently reordered (which would misrepresent the actual body
framing and hide caller bugs).
Implementation
TransferEncodingHeader.encodings(List<TransferEncoding> encodings)
: encodings = List.unmodifiable(encodings) {
if (encodings.isEmpty) {
throw ArgumentError.value(encodings, 'encodings', 'cannot be empty');
}
final chunkedIndex = encodings.indexWhere(
(e) => e.name == TransferEncoding.chunked.name,
);
if (chunkedIndex >= 0 && chunkedIndex != encodings.length - 1) {
throw const FormatException(
'chunked transfer-coding must be the final coding (RFC 9112 6.1)',
);
}
}