Skip to content

Commit ce05ffd

Browse files
authored
Move EmptyHttpResult to Http.Abstractions (#46077)
1 parent a527ac5 commit ce05ffd

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Microsoft.AspNetCore.Http.EndpointFilterInvocationContext
2424
Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.EndpointFilterInvocationContext() -> void
2525
Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator.Current.get -> object!
2626
Microsoft.AspNetCore.Http.EndpointMetadataCollection.GetRequiredMetadata<T>() -> T!
27+
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult
28+
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task!
2729
Microsoft.AspNetCore.Http.HttpValidationProblemDetails
2830
Microsoft.AspNetCore.Http.HttpValidationProblemDetails.Errors.get -> System.Collections.Generic.IDictionary<string!, string![]!>!
2931
Microsoft.AspNetCore.Http.HttpValidationProblemDetails.HttpValidationProblemDetails() -> void
@@ -91,3 +93,4 @@ Microsoft.AspNetCore.Mvc.ProblemDetails.Type.set -> void
9193
override Microsoft.AspNetCore.Http.DefaultEndpointFilterInvocationContext.Arguments.get -> System.Collections.Generic.IList<object?>!
9294
override Microsoft.AspNetCore.Http.DefaultEndpointFilterInvocationContext.GetArgument<T>(int index) -> T
9395
override Microsoft.AspNetCore.Http.DefaultEndpointFilterInvocationContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
96+
static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult!

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Text.Json.Serialization.Metadata;
1616
using Microsoft.AspNetCore.Builder;
1717
using Microsoft.AspNetCore.Http.Features;
18+
using Microsoft.AspNetCore.Http.HttpResults;
1819
using Microsoft.AspNetCore.Http.Json;
1920
using Microsoft.AspNetCore.Http.Metadata;
2021
using Microsoft.AspNetCore.Internal;
@@ -96,11 +97,7 @@ public static partial class RequestDelegateFactory
9697
private static readonly MemberExpression FormFilesExpr = Expression.Property(FormExpr, typeof(IFormCollection).GetProperty(nameof(IFormCollection.Files))!);
9798
private static readonly MemberExpression StatusCodeExpr = Expression.Property(HttpResponseExpr, typeof(HttpResponse).GetProperty(nameof(HttpResponse.StatusCode))!);
9899
private static readonly MemberExpression CompletedTaskExpr = Expression.Property(null, (PropertyInfo)GetMemberInfo<Func<Task>>(() => Task.CompletedTask));
99-
// Due to https://github.com/dotnet/aspnetcore/issues/41330 we cannot reference the EmptyHttpResult type
100-
// but users still need to assert on it as in https://github.com/dotnet/aspnetcore/issues/45063
101-
// so we temporarily work around this here by using reflection to get the actual type.
102-
private static readonly object? EmptyHttpResultInstance = Type.GetType("Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult, Microsoft.AspNetCore.Http.Results")?.GetProperty("Instance")?.GetValue(null, null);
103-
private static readonly NewExpression EmptyHttpResultValueTaskExpr = Expression.New(typeof(ValueTask<object>).GetConstructor(new[] { typeof(IResult) })!, Expression.Constant(EmptyHttpResultInstance));
100+
private static readonly NewExpression EmptyHttpResultValueTaskExpr = Expression.New(typeof(ValueTask<object>).GetConstructor(new[] { typeof(EmptyHttpResult) })!, Expression.Property(null, typeof(EmptyHttpResult), nameof(EmptyHttpResult.Instance)));
104101
private static readonly ParameterExpression TempSourceStringExpr = ParameterBindingMethodCache.TempSourceStringExpr;
105102
private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression.NotEqual(TempSourceStringExpr, Expression.Constant(null));
106103
private static readonly BinaryExpression TempSourceStringNullExpr = Expression.Equal(TempSourceStringExpr, Expression.Constant(null));
@@ -397,7 +394,6 @@ private static Expression[] CreateArgumentsAndInferMetadata(MethodInfo methodInf
397394
private static EndpointFilterDelegate? CreateFilterPipeline(MethodInfo methodInfo, Expression? targetExpression, RequestDelegateFactoryContext factoryContext, Expression<Func<HttpContext, object?>>? targetFactory)
398395
{
399396
Debug.Assert(factoryContext.EndpointBuilder.FilterFactories.Count > 0);
400-
Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found.");
401397
// httpContext.Response.StatusCode >= 400
402398
// ? Task.CompletedTask
403399
// : {
@@ -487,7 +483,6 @@ targetExpression is null
487483

488484
private static Expression MapHandlerReturnTypeToValueTask(Expression methodCall, Type returnType)
489485
{
490-
Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found.");
491486
if (returnType == typeof(void))
492487
{
493488
return Expression.Block(methodCall, EmptyHttpResultValueTaskExpr);
@@ -2209,34 +2204,32 @@ static async Task ExecuteAwaited(ValueTask task)
22092204

22102205
private static ValueTask<object?> ExecuteTaskWithEmptyResult(Task task)
22112206
{
2212-
Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found.");
22132207
static async ValueTask<object?> ExecuteAwaited(Task task)
22142208
{
22152209
await task;
2216-
return EmptyHttpResultInstance;
2210+
return EmptyHttpResult.Instance;
22172211
}
22182212

22192213
if (task.IsCompletedSuccessfully)
22202214
{
2221-
return new ValueTask<object?>(EmptyHttpResultInstance);
2215+
return new ValueTask<object?>(EmptyHttpResult.Instance);
22222216
}
22232217

22242218
return ExecuteAwaited(task);
22252219
}
22262220

22272221
private static ValueTask<object?> ExecuteValueTaskWithEmptyResult(ValueTask valueTask)
22282222
{
2229-
Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found.");
22302223
static async ValueTask<object?> ExecuteAwaited(ValueTask task)
22312224
{
22322225
await task;
2233-
return EmptyHttpResultInstance;
2226+
return EmptyHttpResult.Instance;
22342227
}
22352228

22362229
if (valueTask.IsCompletedSuccessfully)
22372230
{
22382231
valueTask.GetAwaiter().GetResult();
2239-
return new ValueTask<object?>(EmptyHttpResultInstance);
2232+
return new ValueTask<object?>(EmptyHttpResult.Instance);
22402233
}
22412234

22422235
return ExecuteAwaited(valueTask);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
6+
[assembly: TypeForwardedTo(typeof(Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult))]

src/Http/Http.Results/src/PublicAPI.Unshipped.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#nullable enable
2+
*REMOVED*Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult
3+
*REMOVED*Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task!
4+
*REMOVED*static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult!
5+
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
6+
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task! (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
7+
static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult! (forwarded, contained in Microsoft.AspNetCore.Http.Abstractions)
28
Microsoft.AspNetCore.Http.HttpResults.Accepted
39
Microsoft.AspNetCore.Http.HttpResults.Accepted.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task!
410
Microsoft.AspNetCore.Http.HttpResults.Accepted.Location.get -> string?
@@ -62,8 +68,6 @@ Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>.RouteName.get -> st
6268
Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>.RouteValues.get -> Microsoft.AspNetCore.Routing.RouteValueDictionary!
6369
Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>.StatusCode.get -> int
6470
Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>.Value.get -> TValue?
65-
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult
66-
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.ExecuteAsync(Microsoft.AspNetCore.Http.HttpContext! httpContext) -> System.Threading.Tasks.Task!
6771
Microsoft.AspNetCore.Http.HttpResults.FileContentHttpResult
6872
Microsoft.AspNetCore.Http.HttpResults.FileContentHttpResult.ContentType.get -> string!
6973
Microsoft.AspNetCore.Http.HttpResults.FileContentHttpResult.EnableRangeProcessing.get -> bool
@@ -234,7 +238,6 @@ Microsoft.AspNetCore.Http.HttpResults.VirtualFileHttpResult.FileLength.get -> lo
234238
Microsoft.AspNetCore.Http.HttpResults.VirtualFileHttpResult.FileName.get -> string!
235239
Microsoft.AspNetCore.Http.HttpResults.VirtualFileHttpResult.LastModified.get -> System.DateTimeOffset?
236240
Microsoft.AspNetCore.Http.TypedResults
237-
static Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult.Instance.get -> Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult!
238241
static Microsoft.AspNetCore.Http.Results.Bytes(System.ReadOnlyMemory<byte> contents, string? contentType = null, string? fileDownloadName = null, bool enableRangeProcessing = false, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult!
239242
static Microsoft.AspNetCore.Http.Results.Empty.get -> Microsoft.AspNetCore.Http.IResult!
240243
static Microsoft.AspNetCore.Http.Results.Stream(System.Func<System.IO.Stream!, System.Threading.Tasks.Task!>! streamWriterCallback, string? contentType = null, string? fileDownloadName = null, System.DateTimeOffset? lastModified = null, Microsoft.Net.Http.Headers.EntityTagHeaderValue? entityTag = null) -> Microsoft.AspNetCore.Http.IResult!

src/Http/Routing/src/RequestDelegateFilterPipelineBuilder.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Text.Json.Serialization.Metadata;
66
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Http.HttpResults;
78
using Microsoft.AspNetCore.Http.Json;
89
using Microsoft.AspNetCore.Internal;
910
using Microsoft.Extensions.DependencyInjection;
@@ -13,11 +14,6 @@ namespace Microsoft.AspNetCore.Routing;
1314

1415
internal static class RequestDelegateFilterPipelineBuilder
1516
{
16-
// Due to https://github.com/dotnet/aspnetcore/issues/41330 we cannot reference the EmptyHttpResult type
17-
// but users still need to assert on it as in https://github.com/dotnet/aspnetcore/issues/45063
18-
// so we temporarily work around this here by using reflection to get the actual type.
19-
private static readonly object? EmptyHttpResultInstance = Type.GetType("Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult, Microsoft.AspNetCore.Http.Results")?.GetProperty("Instance")?.GetValue(null, null);
20-
2117
public static RequestDelegate Create(RequestDelegate requestDelegate, RequestDelegateFactoryOptions options)
2218
{
2319
Debug.Assert(options.EndpointBuilder != null);
@@ -35,12 +31,11 @@ public static RequestDelegate Create(RequestDelegate requestDelegate, RequestDel
3531

3632
EndpointFilterDelegate filteredInvocation = async (EndpointFilterInvocationContext context) =>
3733
{
38-
Debug.Assert(EmptyHttpResultInstance != null, "Unable to get EmptyHttpResult instance via reflection.");
3934
if (context.HttpContext.Response.StatusCode < 400)
4035
{
4136
await requestDelegate(context.HttpContext);
4237
}
43-
return EmptyHttpResultInstance;
38+
return EmptyHttpResult.Instance;
4439
};
4540

4641
var initialFilteredInvocation = filteredInvocation;

0 commit comments

Comments
 (0)