Skip to content

Commit 40d529e

Browse files
committed
Remove workaround in HeaderPropagationMiddleware
Fixed by #14146 which starts each request on a fresh ExecutionContext
1 parent 75bdd71 commit 40d529e

File tree

2 files changed

+2
-41
lines changed

2 files changed

+2
-41
lines changed

src/Middleware/HeaderPropagation/src/HeaderPropagationMiddleware.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public HeaderPropagationMiddleware(RequestDelegate next, IOptions<HeaderPropagat
3333
_values = values ?? throw new ArgumentNullException(nameof(values));
3434
}
3535

36-
// This needs to be async as otherwise the AsyncLocal could bleed across requests, see https://github.com/aspnet/AspNetCore/issues/13991.
37-
public async Task Invoke(HttpContext context)
36+
public Task Invoke(HttpContext context)
3837
{
3938
// We need to intialize the headers because the message handler will use this to detect misconfiguration.
4039
var headers = _values.Headers ??= new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
@@ -57,7 +56,7 @@ public async Task Invoke(HttpContext context)
5756
}
5857
}
5958

60-
await _next.Invoke(context);
59+
return _next.Invoke(context);
6160
}
6261

6362
private static StringValues GetValue(HttpContext context, HeaderPropagationEntry entry)

src/Middleware/HeaderPropagation/test/HeaderPropagationMiddlewareTest.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -185,43 +185,5 @@ public async Task MultipleEntries_AddsFirstToProduceValue()
185185
Assert.Contains("in", CapturedHeaders.Keys);
186186
Assert.Equal("Test", CapturedHeaders["in"]);
187187
}
188-
189-
[Fact]
190-
public async Task HeaderInRequest_WithBleedAsyncLocal_HasCorrectValue()
191-
{
192-
// Arrange
193-
Configuration.Headers.Add("in");
194-
195-
// Process first request
196-
Context.Request.Headers.Add("in", "dirty");
197-
await Middleware.Invoke(Context);
198-
199-
// Process second request
200-
Context = new DefaultHttpContext();
201-
Context.Request.Headers.Add("in", "test");
202-
await Middleware.Invoke(Context);
203-
204-
// Assert
205-
Assert.Contains("in", CapturedHeaders.Keys);
206-
Assert.Equal(new[] { "test" }, CapturedHeaders["in"]);
207-
}
208-
209-
[Fact]
210-
public async Task NoHeaderInRequest_WithBleedAsyncLocal_DoesNotHaveIt()
211-
{
212-
// Arrange
213-
Configuration.Headers.Add("in");
214-
215-
// Process first request
216-
Context.Request.Headers.Add("in", "dirty");
217-
await Middleware.Invoke(Context);
218-
219-
// Process second request
220-
Context = new DefaultHttpContext();
221-
await Middleware.Invoke(Context);
222-
223-
// Assert
224-
Assert.Empty(CapturedHeaders);
225-
}
226188
}
227189
}

0 commit comments

Comments
 (0)