finalize method

Finalizes the HTTP request in preparation for it being sent.

Freezes all mutable fields and returns a single-subscription ByteStream that emits the body of the request.

The base implementation of this returns an empty ByteStream; subclasses are responsible for creating the return value, which should be single-subscription to ensure that no data is dropped. They should also freeze any additional mutable fields they add that don't make sense to change after the request headers are sent.

Implementation

@mustCallSuper
ByteStream finalize() {
  // TODO(nweiz): freeze headers
  if (finalized) throw StateError("Can't finalize a finalized Request.");
  _finalized = true;
  return const ByteStream(Stream.empty());
}