Dio version: dio: ^3.0.8
When I set Dio header like this
dio.options.headers['Authorization'] = 'dGVzdDp0ZXN0';
I expect request header to look like this
Authorization: Basic dGVzdDp0ZXN0
Not like this (notice that capital "A" was transformed to "a")
authorization: Basic dGVzdDp0ZXN0
Reason for this is HERE. All headers are transformed to lower case.
I can only guess what your motivation for this was, but this is wrong.
Please read about it HERE and HERE
Even Dart team is currently reverting this
https://dart-review.googlesource.com/c/sdk/+/119100
Dio 2.1.5 did not have this behavior. I was able to use AltHttpClient with Dio and headers where left AS IS.
After some inspection I can confirm that version Dio 3.0.7 works as expected, it doesn't change headers casing. Problem is commit by @wendux 12 days ago.
I'm even more sure now that this is bug since entire commit was marked as "code style improvement". Please revert changes.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
Yes, this issue is very much still open
same problem.
Dio version 3.0.8
the bug came to assail me.
I need headers like CamelCase.
user-agent => User-Agent
referer => Referer
content-type => Content-Type
and so on...
as @shaxxx say, please revert changes.
FYI: Dart team has enabled support for case sensitive headers in the new upcoming version.
New Dart (and Flutter) release will support case sensitive headers, so should Dio.
But the RFC clearly states, that headers are case-insensitive.
This means it should not matter if dio sends "content-type" or "Content-Type" or "cOntEnt-TyPE".
The server has the bug here. Not this package.
@masseelch I'm aware what RFC states, and I'm aware how servers should work.
I'm also aware there are millions of servers in the wild that are not acting according to RFC.
Forcing all headers to lowercase does not make Dio act more or less according to RFC.
RFC doesn't care about the headers casing, neither should Dio. Let developers worry about it.
Only possible reasons why Dio forces this:
Are you aware of millions of people using apps that talk with devices running some kind of web server (like TV, Cable, Satellite receivers)? Do you think it realistic for users of my app to contact their cable provider, or maybe manufacturer of hardware to change their behavior?
Authors of Google Chrome are aware of this, yet they're sending 'Authorization' header, not 'authorization'. Why do you think this is the case?
And like I said in my previous post, I don't believe that someone has given any thought about this. Whole commit was marked as "code style improvement". If something breaks previous behavior it's all but not "code style improvement".
RFC doesn't care about the headers casing, neither should Dio. Let developers worry about it.
This indeed is a valid point.
If something breaks previous behavior it's all but not "code style improvement".
Yes. This should be at least a new minor version.
If i think about it, it does not hurt to leave the header key untouched.
Also I believe it is causing the following case:
flutter: headers:
flutter: content-type: application/json; charset=utf-8
flutter: x-auth-token: null
flutter: X-Auth-Token: QcD7S_nbLJ7prcyU95pN
[via LogInterceptor]
I don't mind double assignments of headers that overwrite one another in my codebase (which would be the case if the lowercasing was not the case), but I do mind having to go over it to find out the reason behind these header values.
Both headers were assigned as options.headers['X-Auth-Token'] = ..., but the downcased one was passed to Dio(options) and the latter one was assigned during onRequest in an Interceptor.
Just got bit by this as well.
same problem.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.
Still an issue.
same problem.
same problem.
same problem
same problem.
io_adapter.dart====>>>
options.headers.forEach((k, v) {
##### if header value is null, build BytesBuilder will crash,set preserveHeaderCase true to keep case
request.headers.set(k, v??"null",preserveHeaderCase: true);
});
Most helpful comment
@masseelch I'm aware what RFC states, and I'm aware how servers should work.
I'm also aware there are millions of servers in the wild that are not acting according to RFC.
Forcing all headers to lowercase does not make Dio act more or less according to RFC.
RFC doesn't care about the headers casing, neither should Dio. Let developers worry about it.
Only possible reasons why Dio forces this:
Dart authors are aware of this and decided to revert this same behavior Dio is trying to force.
Are you aware of millions of people using apps that talk with devices running some kind of web server (like TV, Cable, Satellite receivers)? Do you think it realistic for users of my app to contact their cable provider, or maybe manufacturer of hardware to change their behavior?
Authors of Google Chrome are aware of this, yet they're sending 'Authorization' header, not 'authorization'. Why do you think this is the case?
And like I said in my previous post, I don't believe that someone has given any thought about this. Whole commit was marked as "code style improvement". If something breaks previous behavior it's all but not "code style improvement".