encodeHeaders method
Encode the response headers as a QPACK-encoded field section.
The :status pseudo-header is encoded first, followed by regular
headers with lower-cased names. The returned bytes are suitable for
an HTTP/3 HEADERS frame payload.
encoder may be used to emit dynamic table insertions on the QPACK
encoder stream. When omitted, only the static table is used.
Implementation
Uint8List encodeHeaders({QpackEncoder? encoder}) {
final lines = <({String name, String value})>[
(name: ':status', value: statusCode.toString()),
];
for (final entry in headers.entries) {
lines.add((name: entry.key.toLowerCase(), value: entry.value));
}
if (encoder != null) {
return encoder.encodeLines(lines);
}
return QpackEncoder.encodeFieldLines(lines);
}