aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Fix for: Minimal APIs and controllers treat header arrays differently

Open smnsht opened this issue 1 year ago • 6 comments

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

smnsht avatar Oct 05 '24 09:10 smnsht

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.

BrennanConroy avatar Oct 07 '24 17:10 BrennanConroy

My bad.

I've asked him just now.

smnsht avatar Oct 07 '24 19:10 smnsht

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.

BrennanConroy avatar Oct 08 '24 22:10 BrennanConroy

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.

  1. I think a unit test with IEnumerable (other PR) should not be added. This code could not be compiled

dotnet 8.0 - screenshot image

Confirmation would be appreciated

  1. 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

smnsht avatar Oct 09 '24 14:10 smnsht

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 avatar Oct 09 '24 17:10 captainsafia

@captainsafia Thanks. Going to fix that.

smnsht avatar Oct 09 '24 18:10 smnsht