writeTo method

int writeTo(
  1. Uint8List out
)

Writes the head into out, which holds at least bound bytes, and returns how many bytes it took.

Implementation

int writeTo(Uint8List out) {
  out.setRange(0, _statusLine.length, _statusLine);
  var off = _statusLine.length;
  for (final name in _headers.names) {
    if (ResponseFraming.isFramingHeader(name)) continue;
    for (final value in _headers.values(name)) {
      off = _field(out, off, name.lower, value);
    }
  }
  if (_framing.contentType case final contentType?) {
    off = _field(out, off, 'content-type', contentType);
  }
  if (_framing.dateLine case final dateLine?) {
    dateOffset = off + _dateName.length;
    out.setRange(off, off + dateLine.length, dateLine);
    off += dateLine.length;
  } else if (_framing.date case final date?) {
    dateOffset = off + _dateName.length;
    off = _field(out, off, 'date', date);
  }
  if (_framing.contentLength case final contentLength?) {
    off = _latin1(out, off, 'content-length: ');
    off = _digits(out, off, contentLength);
    off = _crlf(out, off);
  }
  if (_transferEncoding case final transferEncoding?) {
    off = _field(out, off, 'transfer-encoding', transferEncoding);
  }
  if (_announceClose) off = _field(out, off, 'connection', 'close');
  return _crlf(out, off);
}