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 all 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
4 changes: 2 additions & 2 deletions src/Hosting/TestHost/src/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
// Copy trailers to the response message when the response stream is complete
contextBuilder.RegisterResponseReadCompleteCallback(context =>
{
var responseTrailersFeature = context.Features.Get<IHttpResponseTrailersFeature>();
var responseTrailersFeature = context.Features.Get<IHttpResponseTrailersFeature>()!;

foreach (var trailer in responseTrailersFeature.Trailers)
{
Expand All @@ -196,7 +196,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
var httpContext = await contextBuilder.SendAsync(cancellationToken);

response.StatusCode = (HttpStatusCode)httpContext.Response.StatusCode;
response.ReasonPhrase = httpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase;
response.ReasonPhrase = httpContext.Features.Get<IHttpResponseFeature>()!.ReasonPhrase;
response.RequestMessage = request;
response.Version = request.Version;

Expand Down
2 changes: 1 addition & 1 deletion src/Hosting/TestHost/src/HttpContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ internal async Task ReturnResponseMessageAsync()
{
newFeatures[pair.Key] = pair.Value;
}
var serverResponseFeature = _httpContext.Features.Get<IHttpResponseFeature>();
var serverResponseFeature = _httpContext.Features.Get<IHttpResponseFeature>()!;
// The client gets a deep copy of this so they can interact with the body stream independently of the server.
var clientResponseFeature = new HttpResponseFeature()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Extensions/src/ResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Clear(this HttpResponse response)
throw new InvalidOperationException("The response cannot be cleared, it has already started sending.");
}
response.StatusCode = 200;
response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = null;
response.HttpContext.Features.Get<IHttpResponseFeature>()!.ReasonPhrase = null;
response.Headers.Clear();
if (response.Body.CanSeek)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Extensions/src/SendFileResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static async Task SendFileAsyncCore(HttpResponse response, string fileNa
{
var useRequestAborted = !cancellationToken.CanBeCanceled;
var localCancel = useRequestAborted ? response.HttpContext.RequestAborted : cancellationToken;
var sendFile = response.HttpContext.Features.Get<IHttpResponseBodyFeature>();
var sendFile = response.HttpContext.Features.Get<IHttpResponseBodyFeature>()!;

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.Features/src/FeatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
return (TFeature?)this[typeof(TFeature)];
}

public void Set<TFeature>(TFeature instance)
public void Set<TFeature>(TFeature? instance)
{
this[typeof(TFeature)] = instance;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Http.Features/src/IFeatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public interface IFeatureCollection : IEnumerable<KeyValuePair<Type, object>>
/// </summary>
/// <typeparam name="TFeature">The feature key.</typeparam>
/// <returns>The requested feature, or null if it is not present.</returns>
TFeature Get<TFeature>();
TFeature? Get<TFeature>();

/// <summary>
/// Sets the given feature in the collection.
/// </summary>
/// <typeparam name="TFeature">The feature key.</typeparam>
/// <param name="instance">The feature value.</param>
void Set<TFeature>(TFeature instance);
void Set<TFeature>(TFeature? instance);
}
}
6 changes: 3 additions & 3 deletions src/Http/Http.Features/src/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Microsoft.AspNetCore.Http.Features.FeatureCollection.FeatureCollection(Microsoft
Microsoft.AspNetCore.Http.Features.FeatureCollection.Get<TFeature>() -> TFeature?
Microsoft.AspNetCore.Http.Features.FeatureCollection.GetEnumerator() -> System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.Type!, object!>>!
Microsoft.AspNetCore.Http.Features.FeatureCollection.IsReadOnly.get -> bool
Microsoft.AspNetCore.Http.Features.FeatureCollection.Set<TFeature>(TFeature instance) -> void
Microsoft.AspNetCore.Http.Features.FeatureCollection.Set<TFeature>(TFeature? instance) -> void
Microsoft.AspNetCore.Http.Features.FeatureCollection.this[System.Type! key].get -> object?
Microsoft.AspNetCore.Http.Features.FeatureCollection.this[System.Type! key].set -> void
Microsoft.AspNetCore.Http.Features.FeatureReference<T>
Expand All @@ -46,10 +46,10 @@ Microsoft.AspNetCore.Http.Features.HttpsCompressionMode.Compress = 2 -> Microsof
Microsoft.AspNetCore.Http.Features.HttpsCompressionMode.Default = 0 -> Microsoft.AspNetCore.Http.Features.HttpsCompressionMode
Microsoft.AspNetCore.Http.Features.HttpsCompressionMode.DoNotCompress = 1 -> Microsoft.AspNetCore.Http.Features.HttpsCompressionMode
Microsoft.AspNetCore.Http.Features.IFeatureCollection
Microsoft.AspNetCore.Http.Features.IFeatureCollection.Get<TFeature>() -> TFeature
Microsoft.AspNetCore.Http.Features.IFeatureCollection.Get<TFeature>() -> TFeature?
Microsoft.AspNetCore.Http.Features.IFeatureCollection.IsReadOnly.get -> bool
Microsoft.AspNetCore.Http.Features.IFeatureCollection.Revision.get -> int
Microsoft.AspNetCore.Http.Features.IFeatureCollection.Set<TFeature>(TFeature instance) -> void
Microsoft.AspNetCore.Http.Features.IFeatureCollection.Set<TFeature>(TFeature? instance) -> void
Microsoft.AspNetCore.Http.Features.IFeatureCollection.this[System.Type! key].get -> object?
Microsoft.AspNetCore.Http.Features.IFeatureCollection.this[System.Type! key].set -> void
Microsoft.AspNetCore.Http.Features.IFormFeature
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http/src/Internal/DefaultHttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override Stream Body
get { return HttpResponseBodyFeature.Stream; }
set
{
var otherFeature = _features.Collection.Get<IHttpResponseBodyFeature>();
var otherFeature = _features.Collection.Get<IHttpResponseBodyFeature>()!;

if (otherFeature is StreamResponseBodyFeature streamFeature
&& streamFeature.PriorFeature != null
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http/src/Internal/ResponseCookies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class ResponseCookies : IResponseCookies
internal ResponseCookies(IFeatureCollection features)
{
_features = features;
Headers = _features.Get<IHttpResponseFeature>().Headers;
Headers = _features.Get<IHttpResponseFeature>()!.Headers;
}

private IHeaderDictionary Headers { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -54,6 +55,8 @@ public async Task Invoke(HttpContext context)
var originalBodyFeature = context.Features.Get<IHttpResponseBodyFeature>();
var originalCompressionFeature = context.Features.Get<IHttpsCompressionFeature>();

Debug.Assert(originalBodyFeature != null);

var compressionBody = new ResponseCompressionBody(context, _provider, originalBodyFeature);
context.Features.Set<IHttpResponseBodyFeature>(compressionBody);
context.Features.Set<IHttpsCompressionFeature>(compressionBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void ApplyAction(RewriteContext context, BackReferenceCollection

if (!string.IsNullOrEmpty(StatusReason))
{
context.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = StatusReason;
context.HttpContext.Features.Get<IHttpResponseFeature>()!.ReasonPhrase = StatusReason;
}

if (!string.IsNullOrEmpty(StatusDescription))
Expand Down
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
Loading