build method

void build(
  1. BytesBuilder builder, {
  2. bool skipZeroContentLength = false,
})

General Library Documentation Undocument By General Corporation & Global Corporation & General Developer

Implementation

void build(BytesBuilder builder, {bool skipZeroContentLength = false}) {
  // per https://tools.ietf.org/html/rfc7230#section-3.3.2
  // A user agent SHOULD NOT send a
  // Content-Length header field when the request message does not
  // contain a payload body and the method semantics do not anticipate
  // such a body.
  String? ignoreHeader = _contentLength == 0 && skipZeroContentLength
      ? HttpHeaders.contentLengthHeader
      : null;
  _headers.forEach((String name, List<String> values) {
    if (ignoreHeader == name) {
      return;
    }
    String originalName = _originalHeaderName(name);
    bool fold = _foldHeader(name);
    var nameData = originalName.codeUnits;
    builder.add(nameData);
    builder.addByte(_CharCode.colon);
    builder.addByte(_CharCode.sp);
    for (int i = 0; i < values.length; i++) {
      if (i > 0) {
        if (fold) {
          builder.addByte(_CharCode.comma);
          builder.addByte(_CharCode.sp);
        } else {
          builder.addByte(_CharCode.cr);
          builder.addByte(_CharCode.lf);
          builder.add(nameData);
          builder.addByte(_CharCode.colon);
          builder.addByte(_CharCode.sp);
        }
      }
      builder.add(values[i].codeUnits);
    }
    builder.addByte(_CharCode.cr);
    builder.addByte(_CharCode.lf);
  });
}