Skip to content

Enable nullable on Kestrel generated code #28792

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

Merged
merged 5 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Microsoft.Net.Http.Headers;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

#nullable enable

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{
internal enum KnownHeaderType
Expand Down Expand Up @@ -6712,7 +6714,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
++arrayIndex;
}
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);

return true;
}
Expand Down Expand Up @@ -12724,7 +12726,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
++arrayIndex;
}
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);

return true;
}
Expand Down Expand Up @@ -12816,7 +12818,7 @@ internal unsafe void CopyToFast(ref BufferWriter<PipeWriter> output)
{
tempBits ^= 0x8000000000000000L;
output.Write(HeaderBytes.Slice(640, 18));
output.WriteNumeric((ulong)ContentLength.Value);
output.WriteNumeric((ulong)ContentLength.GetValueOrDefault());
if (tempBits == 0)
{
return;
Expand Down Expand Up @@ -13266,10 +13268,10 @@ private struct HeaderReferences
public StringValues _AccessControlExposeHeaders;
public StringValues _AccessControlMaxAge;

public byte[] _rawConnection;
public byte[] _rawDate;
public byte[] _rawTransferEncoding;
public byte[] _rawServer;
public byte[]? _rawConnection;
public byte[]? _rawDate;
public byte[]? _rawTransferEncoding;
public byte[]? _rawServer;
}

public partial struct Enumerator
Expand Down Expand Up @@ -14149,7 +14151,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
++arrayIndex;
}
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);

return true;
}
Expand Down
132 changes: 67 additions & 65 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,44 @@
using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;

#nullable enable

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{
internal partial class HttpProtocol : IFeatureCollection
{
private object _currentIHttpRequestFeature;
private object _currentIHttpRequestBodyDetectionFeature;
private object _currentIHttpResponseFeature;
private object _currentIHttpResponseBodyFeature;
private object _currentIRequestBodyPipeFeature;
private object _currentIHttpRequestIdentifierFeature;
private object _currentIServiceProvidersFeature;
private object _currentIHttpRequestLifetimeFeature;
private object _currentIHttpConnectionFeature;
private object _currentIRouteValuesFeature;
private object _currentIEndpointFeature;
private object _currentIHttpAuthenticationFeature;
private object _currentIHttpRequestTrailersFeature;
private object _currentIQueryFeature;
private object _currentIFormFeature;
private object _currentIHttpUpgradeFeature;
private object _currentIHttp2StreamIdFeature;
private object _currentIHttpResponseTrailersFeature;
private object _currentIResponseCookiesFeature;
private object _currentIItemsFeature;
private object _currentITlsConnectionFeature;
private object _currentIHttpWebSocketFeature;
private object _currentISessionFeature;
private object _currentIHttpMaxRequestBodySizeFeature;
private object _currentIHttpMinRequestBodyDataRateFeature;
private object _currentIHttpMinResponseDataRateFeature;
private object _currentIHttpBodyControlFeature;
private object _currentIHttpResetFeature;
private object? _currentIHttpRequestFeature;
private object? _currentIHttpRequestBodyDetectionFeature;
private object? _currentIHttpResponseFeature;
private object? _currentIHttpResponseBodyFeature;
private object? _currentIRequestBodyPipeFeature;
private object? _currentIHttpRequestIdentifierFeature;
private object? _currentIServiceProvidersFeature;
private object? _currentIHttpRequestLifetimeFeature;
private object? _currentIHttpConnectionFeature;
private object? _currentIRouteValuesFeature;
private object? _currentIEndpointFeature;
private object? _currentIHttpAuthenticationFeature;
private object? _currentIHttpRequestTrailersFeature;
private object? _currentIQueryFeature;
private object? _currentIFormFeature;
private object? _currentIHttpUpgradeFeature;
private object? _currentIHttp2StreamIdFeature;
private object? _currentIHttpResponseTrailersFeature;
private object? _currentIResponseCookiesFeature;
private object? _currentIItemsFeature;
private object? _currentITlsConnectionFeature;
private object? _currentIHttpWebSocketFeature;
private object? _currentISessionFeature;
private object? _currentIHttpMaxRequestBodySizeFeature;
private object? _currentIHttpMinRequestBodyDataRateFeature;
private object? _currentIHttpMinResponseDataRateFeature;
private object? _currentIHttpBodyControlFeature;
private object? _currentIHttpResetFeature;

private int _featureRevision;

private List<KeyValuePair<Type, object>> MaybeExtra;
private List<KeyValuePair<Type, object>>? MaybeExtra;

private void FastReset()
{
Expand Down Expand Up @@ -87,7 +89,7 @@ internal void ResetFeatureCollection()
_featureRevision++;
}

private object ExtraFeatureGet(Type key)
private object? ExtraFeatureGet(Type key)
{
if (MaybeExtra == null)
{
Expand Down Expand Up @@ -126,11 +128,11 @@ private void ExtraFeatureSet(Type key, object value)

int IFeatureCollection.Revision => _featureRevision;

object IFeatureCollection.this[Type key]
object? IFeatureCollection.this[Type key]
{
get
{
object feature = null;
object? feature = null;
if (key == typeof(IHttpRequestFeature))
{
feature = _currentIHttpRequestFeature;
Expand Down Expand Up @@ -369,137 +371,137 @@ object IFeatureCollection.this[Type key]
}
else
{
ExtraFeatureSet(key, value);
ExtraFeatureSet(key, value!); // TODO: What happens if you set an extra feature with a null value?
}
}
}

TFeature IFeatureCollection.Get<TFeature>()
{
TFeature feature = default;
TFeature? feature = default;
if (typeof(TFeature) == typeof(IHttpRequestFeature))
{
feature = (TFeature)_currentIHttpRequestFeature;
feature = (TFeature?)_currentIHttpRequestFeature;
}
else if (typeof(TFeature) == typeof(IHttpRequestBodyDetectionFeature))
{
feature = (TFeature)_currentIHttpRequestBodyDetectionFeature;
feature = (TFeature?)_currentIHttpRequestBodyDetectionFeature;
}
else if (typeof(TFeature) == typeof(IHttpResponseFeature))
{
feature = (TFeature)_currentIHttpResponseFeature;
feature = (TFeature?)_currentIHttpResponseFeature;
}
else if (typeof(TFeature) == typeof(IHttpResponseBodyFeature))
{
feature = (TFeature)_currentIHttpResponseBodyFeature;
feature = (TFeature?)_currentIHttpResponseBodyFeature;
}
else if (typeof(TFeature) == typeof(IRequestBodyPipeFeature))
{
feature = (TFeature)_currentIRequestBodyPipeFeature;
feature = (TFeature?)_currentIRequestBodyPipeFeature;
}
else if (typeof(TFeature) == typeof(IHttpRequestIdentifierFeature))
{
feature = (TFeature)_currentIHttpRequestIdentifierFeature;
feature = (TFeature?)_currentIHttpRequestIdentifierFeature;
}
else if (typeof(TFeature) == typeof(IServiceProvidersFeature))
{
feature = (TFeature)_currentIServiceProvidersFeature;
feature = (TFeature?)_currentIServiceProvidersFeature;
}
else if (typeof(TFeature) == typeof(IHttpRequestLifetimeFeature))
{
feature = (TFeature)_currentIHttpRequestLifetimeFeature;
feature = (TFeature?)_currentIHttpRequestLifetimeFeature;
}
else if (typeof(TFeature) == typeof(IHttpConnectionFeature))
{
feature = (TFeature)_currentIHttpConnectionFeature;
feature = (TFeature?)_currentIHttpConnectionFeature;
}
else if (typeof(TFeature) == typeof(IRouteValuesFeature))
{
feature = (TFeature)_currentIRouteValuesFeature;
feature = (TFeature?)_currentIRouteValuesFeature;
}
else if (typeof(TFeature) == typeof(IEndpointFeature))
{
feature = (TFeature)_currentIEndpointFeature;
feature = (TFeature?)_currentIEndpointFeature;
}
else if (typeof(TFeature) == typeof(IHttpAuthenticationFeature))
{
feature = (TFeature)_currentIHttpAuthenticationFeature;
feature = (TFeature?)_currentIHttpAuthenticationFeature;
}
else if (typeof(TFeature) == typeof(IHttpRequestTrailersFeature))
{
feature = (TFeature)_currentIHttpRequestTrailersFeature;
feature = (TFeature?)_currentIHttpRequestTrailersFeature;
}
else if (typeof(TFeature) == typeof(IQueryFeature))
{
feature = (TFeature)_currentIQueryFeature;
feature = (TFeature?)_currentIQueryFeature;
}
else if (typeof(TFeature) == typeof(IFormFeature))
{
feature = (TFeature)_currentIFormFeature;
feature = (TFeature?)_currentIFormFeature;
}
else if (typeof(TFeature) == typeof(IHttpUpgradeFeature))
{
feature = (TFeature)_currentIHttpUpgradeFeature;
feature = (TFeature?)_currentIHttpUpgradeFeature;
}
else if (typeof(TFeature) == typeof(IHttp2StreamIdFeature))
{
feature = (TFeature)_currentIHttp2StreamIdFeature;
feature = (TFeature?)_currentIHttp2StreamIdFeature;
}
else if (typeof(TFeature) == typeof(IHttpResponseTrailersFeature))
{
feature = (TFeature)_currentIHttpResponseTrailersFeature;
feature = (TFeature?)_currentIHttpResponseTrailersFeature;
}
else if (typeof(TFeature) == typeof(IResponseCookiesFeature))
{
feature = (TFeature)_currentIResponseCookiesFeature;
feature = (TFeature?)_currentIResponseCookiesFeature;
}
else if (typeof(TFeature) == typeof(IItemsFeature))
{
feature = (TFeature)_currentIItemsFeature;
feature = (TFeature?)_currentIItemsFeature;
}
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
{
feature = (TFeature)_currentITlsConnectionFeature;
feature = (TFeature?)_currentITlsConnectionFeature;
}
else if (typeof(TFeature) == typeof(IHttpWebSocketFeature))
{
feature = (TFeature)_currentIHttpWebSocketFeature;
feature = (TFeature?)_currentIHttpWebSocketFeature;
}
else if (typeof(TFeature) == typeof(ISessionFeature))
{
feature = (TFeature)_currentISessionFeature;
feature = (TFeature?)_currentISessionFeature;
}
else if (typeof(TFeature) == typeof(IHttpMaxRequestBodySizeFeature))
{
feature = (TFeature)_currentIHttpMaxRequestBodySizeFeature;
feature = (TFeature?)_currentIHttpMaxRequestBodySizeFeature;
}
else if (typeof(TFeature) == typeof(IHttpMinRequestBodyDataRateFeature))
{
feature = (TFeature)_currentIHttpMinRequestBodyDataRateFeature;
feature = (TFeature?)_currentIHttpMinRequestBodyDataRateFeature;
}
else if (typeof(TFeature) == typeof(IHttpMinResponseDataRateFeature))
{
feature = (TFeature)_currentIHttpMinResponseDataRateFeature;
feature = (TFeature?)_currentIHttpMinResponseDataRateFeature;
}
else if (typeof(TFeature) == typeof(IHttpBodyControlFeature))
{
feature = (TFeature)_currentIHttpBodyControlFeature;
feature = (TFeature?)_currentIHttpBodyControlFeature;
}
else if (typeof(TFeature) == typeof(IHttpResetFeature))
{
feature = (TFeature)_currentIHttpResetFeature;
feature = (TFeature?)_currentIHttpResetFeature;
}
else if (MaybeExtra != null)
{
feature = (TFeature)(ExtraFeatureGet(typeof(TFeature)));
feature = (TFeature?)(ExtraFeatureGet(typeof(TFeature)));
}

if (feature == null)
{
feature = ConnectionFeatures.Get<TFeature>();
}

return feature;
return feature!;
}

void IFeatureCollection.Set<TFeature>(TFeature feature)
Expand Down Expand Up @@ -619,7 +621,7 @@ void IFeatureCollection.Set<TFeature>(TFeature feature)
}
else
{
ExtraFeatureSet(typeof(TFeature), feature);
ExtraFeatureSet(typeof(TFeature), feature!); // TODO: What happens if you set an extra feature with a null value?
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void AppendContentLength(ReadOnlySpan<byte> value)
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encoding customEncoding)
private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encoding? customEncoding)
{
if (_contentLength.HasValue)
{
Expand All @@ -105,7 +105,7 @@ private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encodin

// long.MaxValue = 9223372036854775807 (19 chars)
Span<char> decodedChars = stackalloc char[20];
var numChars = customEncoding.GetChars(value, decodedChars);
var numChars = customEncoding!.GetChars(value, decodedChars);
long parsed = -1;

if (numChars > 19 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;

#nullable enable

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{
internal partial class Http2Connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;

#nullable enable

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
{
internal static partial class HttpUtilities
Expand Down
Loading