-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dio is forcing headers to lowercase #641
Comments
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. |
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. |
FYI: Dart team has enabled support for case sensitive headers in the new upcoming version. |
But the RFC clearly states, that headers are case-insensitive. |
@masseelch I'm aware what RFC states, and I'm aware how servers should work.
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". |
This indeed is a valid point.
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:
[via 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 |
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. |
1 similar comment
same problem. |
same problem |
same problem. |
io_adapter.dart====>>>
|
Same problem. Has anyone gotten a solution yet? |
same problem. |
Same problem. Has anyone gotten a solution yet? |
should change io_adapter.dart like this. |
same problem :/ Edit: Btw, @vickyleu 's solution solves my issue with old device returning 400 Bad Request |
@vickyleu how can I apply your fix? |
If someone still having this issue, I recommend you to use the HttpClient class from dart:io. I fixed it with the following code block: HttpClient client = new HttpClient();
await client
.getUrl(Uri.parse("YOUR URL"))
.then((HttpClientRequest request) {
request.headers.set(
"Authorization",
"Bearer TOKEN",
preserveHeaderCase: true,
);
// Optionally write to the request object...
// Then call close.
return request.close();
}).then((HttpClientResponse response) {
final completer = Completer<String>();
final contents = StringBuffer();
response.transform(utf8.decoder).listen((data) {
contents.write(data);
print(data);
}, onDone: () => completer.complete(contents.toString()));
}); THIS CODE BLOCK WILL NOT WORK IN FLUTTER WEB, use http or Dio packages instead. I suggest you check out the official documentation: |
Yes, this was also my workaround, but I don't think it's that nice. I'd prefer if dio would implement some property that would propagate to underlying client to set this. |
Just got bit by this as well... tracking it down took a good 4 hours :/
My workaround was, instead of editing an already existing file of dio, I found it safer to copy the adapter from io_adapter.dart to another file in my own project and do the changes there. Then I used httpClientAdapter property of my Dio client to use it. I shared the gist here in case anyone is interested. With that being said, I do think dio should implement a way (like a flag) for us to be able to disable case-insensitive header names, as workarounds like this are dirty. |
still no updates of dio to support this ? |
same problem |
Should be opened |
Should be opened. |
Hey guys. I saw there is a commit that removes Also, can anyone provide any commit link that the Dart team reverted in the previous Dart SDK? That helps to apply new fixes too. |
I hope this gets fixed soon. Still facing the issue. Since we are newly making the api contract, we are migrating to case-insensitive headers. |
This issue still alive. I am facing the same issue. Please solve this out, even adding a flag could help the ones facing this issue. |
The issue is 'closed' but I keep experiencing this issue in version 5.3.2. |
Same the issue is 'closed' but I keep experiencing this issue in version 5.3.2. |
We no longer handle issues before 12th Feb 2023. Please submit new issues with new requirements. |
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.
The text was updated successfully, but these errors were encountered: