void StreamEncoderImpl::endEncode() {
  if (chunk_encoding_) {
    connection_.buffer().addFragments({LAST_CHUNK, CRLF});
  }

  flushOutput(true);
  connection_.onEncodeComplete();
  // With CONNECT or TCP tunneling, half-closing the connection is used to signal end stream.
  if (connect_request_ || is_tcp_tunneling_) {
    connection_.connection().close(Network::ConnectionCloseType::FlushWriteAndDelay);
  }
}
void StreamEncoderImpl::endEncode() {
  if (chunk_encoding_) {
    connection_.buffer().addFragments({LAST_CHUNK, CRLF});
  }

  flushOutput(true);
  connection_.onEncodeComplete();
   
  if (connect_request_ || is_tcp_tunneling_) {
    connection_.connection().close(Network::ConnectionCloseType::FlushWriteAndDelay);
  }
}