[Breaking Change Request] HttpHeaders allows cased header fields

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:

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.

Proposed implementation


@lrhn @mit-mit @a-siva

Author: Fantashit

1 thought on “[Breaking Change Request] HttpHeaders allows cased header fields

  1. @Hixie One can say that Dart’s HttpClient also breaks the standard.
    If standard says that headers are case insensitive why force it to lowercase?
    Any developer familiar with the fact that headers are case insensitive will expect it to be passed AS IS from HttpClient. There is no single reason to mangle with headers in the first place.

    I believe this change is going in the wrong direction to begin with. Instead of making breaking changes why not refactor HttpClient internals so anyone can overload/re-implement parts they want to change. This would allow people to relatively easy change default behavior and would make everyone happy.

Comments are closed.