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 = MessageBuilder.createRandomId();
}
contentType = ContentTypeHeader.from(mediaType,
charset: mediaType.top == MediaToptype.text
? MessageBuilder.getCharacterSetName(characterSet)
: null,
boundary: multiPartBoundary);
if (name != null) {
contentType!.parameters['name'] = '"$name"';
}
if (parameters?.isNotEmpty ?? false) {
contentType!.parameters.addAll(parameters!);
}
}