decodeHeaders static method

Http3Response decodeHeaders(
  1. Uint8List bytes, {
  2. QpackDecoder? decoder,
})

Decode a QPACK-encoded field section into an Http3Response.

Extracts the :status pseudo-header and treats the remainder as regular headers. If :status cannot be parsed as an integer, it defaults to 0.

decoder may be used to decode dynamic table references and to track the required insert count for acknowledgment.

Implementation

static Http3Response decodeHeaders(Uint8List bytes, {QpackDecoder? decoder}) {
  final lines = decoder != null
      ? decoder.decodeLines(bytes)
      : QpackDecoder.decodeFieldLines(bytes);

  int statusCode = 0;
  final headers = <String, String>{};

  for (final line in lines) {
    if (line.name == ':status') {
      statusCode = int.tryParse(line.value) ?? 0;
    } else {
      headers[line.name] = line.value;
    }
  }

  return Http3Response(statusCode: statusCode, headers: headers);
}