aspnetcore
aspnetcore copied to clipboard
Fix for: Minimal APIs and controllers treat header arrays differently
Fix for: Minimal APIs and controllers treat header arrays differently #54978
Alter BindParameterFromProperty(...) method
Description
The root cause of the issue is in GetValueFromProperty(...) behavior - it returns an Expression that evaluates httpContext.Request.Headers[key]. What we want, is to call httpContext.Request.Headers.GetCommaSeparatedValues(key) when the source is "header" and [FromHeader] is attached to an array.
GetCommaSeparatedValues(key) is an extension method, implemented as ParsingHelpers.GetHeaderSplit(IHeaderDictionary, string)
Fixes #54978
There is an active PR for this that has gone through some review and iterations.
If you want to work on this bug you should check with the original PR author and see if they aren't going to work on their fix anymore so that you can take over.
My bad.
I've asked him just now.
Thanks for checking with them, looks like you're good to go.
I'd recommend taking a look at their PR and the reviews that took place to get an idea of what the current change might be missing.
I'd recommend taking a look at their PR and the reviews that took place to get an idea of what the current change might be missing.
- I think a unit test with IEnumerable
(other PR) should not be added. This code could not be compiled
dotnet 8.0 - screenshot
Confirmation would be appreciated
- I see there are changes in RequestDelegateGenerator.cs in other PR. I don't know yet why this change is needed, but I noticed it was explicitly requested by the maintainer. My current understanding is that I should figure this out and properly implement it.
Confirmation would be appreciated
I see there are changes in RequestDelegateGenerator.cs in other PR. I don't know yet why this change is needed, but I noticed it was explicitly requested by the maintainer. My current understanding is that I should figure this out and properly implement it.
The Request Delegate Generator is the source generator implementation that compiles arbitrary delegates to RequestDelegates when you are using native AoT. The behavior between the source generator and non-source generator based implementations should be the same which is why I provided that feedback.
I think a unit test with IEnumerable (other PR) should not be added. This code could not be compiled
This error comes from our analyzers. We'll probably want to update them so they account for the expanded support.
Also, FWIW, I do think it is probably sufficient for us to just support arrays in this binding since that's what we do elsewhere for parameters.
@captainsafia Thanks. Going to fix that.