Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Oct 13, 2023
1 parent 0af3b5b commit 1ec8e68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -234,4 +234,17 @@ internal static bool ShouldSkipHeader(string name)
{
return name.StartsWith(':') || GrpcProtocolConstants.FilteredHeaders.Contains(name);
}

internal static IHttpRequestLifetimeFeature GetRequestLifetimeFeature(HttpContext httpContext)
{
var lifetimeFeature = httpContext.Features.Get<IHttpRequestLifetimeFeature>();
if (lifetimeFeature is null)
{
// This should only run in tests where the HttpContext is manually created.
lifetimeFeature = new HttpRequestLifetimeFeature();
httpContext.Features.Set(lifetimeFeature);
}

return lifetimeFeature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public HttpContextStreamReader(HttpContextServerCallContext serverCallContext, F
// This is done to avoid a race condition when reading them from HttpContext later when running in a separate thread.
_bodyReader = _serverCallContext.HttpContext.Request.BodyReader;
// Copy lifetime feature because HttpContext.RequestAborted on .NET 6 doesn't return the real cancellation token.
_requestLifetimeFeature = _serverCallContext.HttpContext.Features.Get<IHttpRequestLifetimeFeature>()!;
_requestLifetimeFeature = GrpcProtocolHelpers.GetRequestLifetimeFeature(_serverCallContext.HttpContext);
}

public TRequest Current { get; private set; } = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public HttpContextStreamWriter(HttpContextServerCallContext context, Action<TRes
// This is done to avoid a race condition when reading them from HttpContext later when running in a separate thread.
_bodyWriter = context.HttpContext.Response.BodyWriter;
// Copy lifetime feature because HttpContext.RequestAborted on .NET 6 doesn't return the real cancellation token.
_requestLifetimeFeature = context.HttpContext.Features.Get<IHttpRequestLifetimeFeature>()!;
_requestLifetimeFeature = GrpcProtocolHelpers.GetRequestLifetimeFeature(context.HttpContext);
}

public WriteOptions? WriteOptions
Expand Down

0 comments on commit 1ec8e68

Please sign in to comment.