Check for empty list instead of null value. - #630
Conversation
| RequestHeaders requestHeader = request.GetTypedHeaders(); | ||
| if (requestHeader != null && requestHeader.AcceptCharset != null) | ||
| // Starting from ASP .NET Core 3.0 AcceptCharset returns an empty collection instead of null. | ||
| if (requestHeader?.AcceptCharset.Count > 0) |
There was a problem hiding this comment.
| if (requestHeader?.AcceptCharset.Count > 0) | |
| if (requestHeader?.AcceptCharset?.Count > 0) |
Let's be compatible with both versions
There was a problem hiding this comment.
AFAIR this repo is for ASP .NET Core 3+. So it can't be ran with ASP .NET Core 2.x. This change make sense for OData/WebApi repo. Correct me if I'm wrong.
There was a problem hiding this comment.
I'd also lean in favor of the AcceptCharset?.Count check
There was a problem hiding this comment.
But the standard lib explicitly marks the properties that can be null as nullable in newer .NET versions e.g.: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.headers.requestheaders.cachecontrol?view=aspnetcore-6.0
I don't think that was the case for .NET Core 3.1 so it's hard to tell from just looking at the property whether it's safe to assume it can't be null.
| MediaTypeHeaderValue currentContentType = GetContentType(response.Headers[HeaderNames.ContentType].FirstOrDefault()); | ||
| RequestHeaders requestHeader = request.GetTypedHeaders(); | ||
| if (requestHeader != null && requestHeader.AcceptCharset != null) | ||
| // Starting from ASP .NET Core 3.0 AcceptCharset returns an empty collection instead of null. |
There was a problem hiding this comment.
Can you please add a test for this?
Co-authored-by: John Gathogo <john.gathogo@gmail.com>
No description provided.