void _writeHeader()

in lib/src/http_impl.dart [788:841]


  void _writeHeader() {
    BytesBuilder buffer = _CopyingBytesBuilder(_OUTGOING_BUFFER_SIZE);

    // Write status line.
    if (headers.protocolVersion == "1.1") {
      buffer.add(Const.HTTP11);
    } else {
      buffer.add(Const.HTTP10);
    }
    buffer.addByte(CharCode.SP);
    buffer.add(statusCode.toString().codeUnits);
    buffer.addByte(CharCode.SP);
    buffer.add(reasonPhrase.codeUnits);
    buffer.addByte(CharCode.CR);
    buffer.addByte(CharCode.LF);

    var session = _httpRequest._session;
    if (session != null && !session.destroyed) {
      // Mark as not new.
      session.markOld();
      // Make sure we only send the current session id.
      bool found = false;
      for (int i = 0; i < cookies.length; i++) {
        if (cookies[i].name.toUpperCase() == DART_SESSION_ID) {
          cookies[i]
            ..value = session.id
            ..httpOnly = true
            ..path = "/";
          found = true;
        }
      }
      if (!found) {
        var cookie = Cookie(DART_SESSION_ID, session.id);
        cookies.add(cookie
          ..httpOnly = true
          ..path = "/");
      }
    }
    // Add all the cookies set to the headers.
    if (_cookies != null) {
      _cookies.forEach((cookie) {
        headers.add(HttpHeaders.SET_COOKIE, cookie);
      });
    }

    headers.finalize();

    // Write headers.
    headers.build(buffer);
    buffer.addByte(CharCode.CR);
    buffer.addByte(CharCode.LF);
    Uint8List headerBytes = buffer.takeBytes();
    _outgoing.setHeader(headerBytes, headerBytes.length);
  }