Skip to content

Commit dcf6c20

Browse files
Sunset policy should be reported during non-success if possible
1 parent e731568 commit dcf6c20

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/Common/src/Common/DefaultApiVersionReporter.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
7979
AddApiVersionHeader( headers, apiSupportedVersionsName, apiVersionModel.SupportedApiVersions );
8080
AddApiVersionHeader( headers, apiDeprecatedVersionsName, apiVersionModel.DeprecatedApiVersions );
8181

82-
#if NETFRAMEWORK
83-
var statusCode = (int) response.StatusCode;
84-
#else
85-
var context = response.HttpContext;
86-
var statusCode = response.StatusCode;
87-
#endif
88-
89-
if ( statusCode < 200 || statusCode > 299 )
90-
{
91-
return;
92-
}
93-
9482
#if NETFRAMEWORK
9583
if ( response.RequestMessage is not HttpRequestMessage request ||
9684
request.GetActionDescriptor()?.GetApiVersionMetadata() is not ApiVersionMetadata metadata )
@@ -102,6 +90,8 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
10290
var policyManager = request.GetConfiguration().DependencyResolver.GetSunsetPolicyManager();
10391
var version = request.GetRequestedApiVersion();
10492
#else
93+
var context = response.HttpContext;
94+
10595
if ( context.GetEndpoint()?.Metadata.GetMetadata<ApiVersionMetadata>() is not ApiVersionMetadata metadata )
10696
{
10797
return;
@@ -113,8 +103,8 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
113103
#endif
114104

115105
if ( policyManager.TryGetPolicy( name, version, out var policy ) ||
116-
( !string.IsNullOrEmpty( name ) && policyManager.TryGetPolicy( name, out policy ) ) ||
117-
( version != null && policyManager.TryGetPolicy( version, out policy ) ) )
106+
( !string.IsNullOrEmpty( name ) && policyManager.TryGetPolicy( name, out policy ) ) ||
107+
( version != null && policyManager.TryGetPolicy( version, out policy ) ) )
118108
{
119109
response.WriteSunsetPolicy( policy );
120110
}

0 commit comments

Comments
 (0)