Description
The intended change in behavior
Current implementation of HttpHeaders
will always force all header fields to be lower-cased. An optional named parameters will be added to following methods to loosen this restriction.
Methods in abstract Class HttpHeaders
will be changed:
void add(String name, Object value);
// change to
void add(String name, Object value, {bool preserveHeaderCase: false});
add
will be functionally the same as before. What's new?
Header names will be always converted to lower-case unless preserveHeaderCase
is set to true. If two header names are the same when converted to lower-case, they are considered to be the same header, with one set of values. The current case of a header is the name assigned by the last set
or add
call for that header.
void set(String name, Object value);
// change to
void set(String name, Object value, {bool preserveHeaderCase: false});
set
will remove the entity that has the same lower-cased header field and perform an add
.
The implementation class _HttpHeaders
in dart:io will be modified accordingly.
The justification
Header fields of HttpHeaders
are case-insensitive according to specification. Implementation class _HttpHeaders
will convert all header fields into lowercases by default. This is expected behavior. However, some servers do rely on cased header fields.
Relative issues:
#33501
#25120
Expected impact
Code that has classes extends/implements the HttpHeaders
will now get compile time error.
Steps for mitigation
Code that doesn't have classes extends/implements abstract HttpHeaders
will not need to make any change. Otherwise, update add()
and set()
as showed above.