ResponseHead constructor

ResponseHead(
  1. Response response,
  2. ResponseFraming framing
)

Implementation

factory ResponseHead(Response response, ResponseFraming framing) {
  final headers = response.headers;
  final statusLine = _statusLineFor(response.statusCode);
  final transferEncoding = framing.transferEncoding?.join(', ');
  var bound = statusLine.length + 2;
  for (final name in headers.names) {
    for (final value in headers.values(name)) {
      bound += name.lower.length + value.length + 4;
    }
  }
  if (framing.contentType case final contentType?) {
    bound += 'content-type: '.length + contentType.length + 2;
  }
  if (framing.date case final date?) {
    bound += 'date: '.length + date.length + 2;
  }
  if (transferEncoding != null) {
    bound += 'transfer-encoding: '.length + transferEncoding.length + 2;
  }
  bound += 'content-length: '.length + _maxContentLengthDigits + 2;
  if (framing.connection case final connection?) {
    bound += 'connection: '.length + connection.value.length + 2;
  }
  return ResponseHead._(
    statusLine,
    headers,
    framing,
    transferEncoding,
    bound,
  );
}