Skip to content

Commit 4ea6832

Browse files
GarrettBeattyclaude
andcommitted
Fix InvokeFeatures.Set to bump revision for body-wrapping middleware
InvokeFeatures.Set<TFeature> was updating the feature dictionary without incrementing _containerRevision. ASP.NET Core's FeatureReferences cache uses Collection.Revision to detect feature swaps; without the bump, cached feature references stay stale after middleware (e.g. OutputCache, ResponseCompression) replaces a feature via HttpContext.Response.Body = wrapper. The result was that response writes bypassed the wrapper entirely, so OutputCache cached zero-byte bodies and subsequent cached responses returned empty. Resolves #1702. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0c8b3c1 commit 4ea6832

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.AspNetCoreServer",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Fix InvokeFeatures.Set<TFeature> to bump the feature collection revision so middleware that wraps the response body (e.g. OutputCache, ResponseCompression) is properly visible to ASP.NET Core's FeatureReferences cache. Resolves https://github.com/aws/aws-lambda-dotnet/issues/1702 where IOutputCache stored empty response bodies."
8+
]
9+
}
10+
]
11+
}

Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/InvokeFeatures.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
117117

118118
public void Set<TFeature>(TFeature instance)
119119
{
120-
if (instance == null)
121-
return;
122-
123-
_features[typeof(TFeature)] = instance;
120+
// Delegate to the indexer so _containerRevision is bumped, otherwise
121+
// ASP.NET Core's FeatureReferences cache will return stale feature
122+
// references after middleware (e.g. OutputCache, ResponseCompression)
123+
// wraps the response body via HttpContext.Response.Body = wrapper.
124+
this[typeof(TFeature)] = instance;
124125
}
125126

126127
IEnumerator IEnumerable.GetEnumerator()

0 commit comments

Comments
 (0)