toString method

  1. @override
String toString()
inherited

Converts the media type to a string.

This will produce a valid HTTP media type.

Implementation

@override
String toString() {
  final buffer = StringBuffer()
    ..write(type)
    ..write('/')
    ..write(subtype);

  parameters.forEach((attribute, value) {
    buffer.write('; $attribute=');
    if (nonToken.hasMatch(value)) {
      buffer
        ..write('"')
        ..write(
            value.replaceAllMapped(_escapedChar, (match) => '\\${match[0]}'))
        ..write('"');
    } else {
      buffer.write(value);
    }
  });

  return buffer.toString();
}