setContentType method
void
setContentType(})
Creates the content-type based on the specified mediaType.
Optionally you can specify the characterSet, multiPartBoundary,
name or other parameters.
Implementation
void setContentType(
MediaType mediaType, {
CharacterSet? characterSet,
String? multiPartBoundary,
String? name,
Map<String, String>? parameters,
}) {
if (mediaType.isMultipart && multiPartBoundary == null) {
// multiPartBoundary is null and this is a multipart ->
// define a default boundary:
// ignore: parameter_assignments
multiPartBoundary = MessageBuilder.createRandomId();
}
final contentType = ContentTypeHeader.from(
mediaType,
charset: mediaType.top == MediaToptype.text
? MessageBuilder.getCharacterSetName(characterSet)
: null,
boundary: multiPartBoundary,
);
if (name != null) {
contentType.parameters['name'] = '"$name"';
}
if (parameters != null && parameters.isNotEmpty) {
contentType.parameters.addAll(parameters);
}
this.contentType = contentType;
}