headerSet method
Sets a HTTP header
Sets a HTTP header to the name
and String value
to the HTTP
response. Any existing header(s) with the same name are removed.
The name is case-insensitive. The name is considered the same, whether it is represented using uppercase or lowercase letters.
The value is case sensitive.
Do not use this method for setting the content type. Use the contentType member instead.
Do not use this method for setting cookies. Use the cookieAdd and cookieDelete methods. An exception will be raised if the name matches "set-cookie".
Implementation
void headerSet(String name, String value) {
ArgumentError.checkNotNull(name);
ArgumentError.checkNotNull(value);
if (name.isEmpty) {
throw ArgumentError.value(name, 'name', 'Empty string');
}
if (_headersOutputted) {
throw StateError('Header already outputted');
}
final canonicalName = _headerCanonicalName(name);
if (canonicalName == _headerCanonicalName('content-type')) {
throw ArgumentError.value(
canonicalName, 'name', 'use contentType to set Content-Type');
}
if (canonicalName == _headerCanonicalName('set-cookie')) {
throw ArgumentError.value(
canonicalName, 'name', 'use cookieAdd to set a cookie');
}
_headers[canonicalName] = [value];
}