Dart (Flutter) Dio Library Sends All HTTP Headers in Lowercase

2021-03-20 22:05 (3 years ago) ytyng

Dart (Flutter) dio library

https://pub.dev/packages/dio

is more convenient compared to other commonly used HTTP libraries because it allows for easy handling of cancellations, GET parameters, timeouts, JSON, etc.

However, in version 3.x, there is an issue where all HTTP headers are sent in lowercase.

In other words,

await Dio().get(
endpointUrl,
options: Options(
headers: {
'Authorization': 'xxxxxx'
}
),
);

if you write it like this, the actual header will be authorization: xxxxxx.

Some servers may not recognize the header.

https://github.com/flutterchina/dio/issues/641

This issue is discussed here, and while the RFC states that headers should be treated case-insensitively, in reality, some server-side implementations may distinguish between cases, making it challenging for such use cases.

However, this might be fixed in the upcoming V 4.0.0, which is currently under a pull request. Let's wait and see.

https://github.com/flutterchina/dio/pull/1082

Incidentally, when I switched to the http library and tested, the headers were also converted to lowercase in the same way.

Current rating: 5

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011