File tree 1 file changed +5
-3
lines changed
src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/AspNetCore6Plus
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ public override Task FlushAsync(CancellationToken cancellationToken)
39
39
{
40
40
if ( ! Disabled && ! _isContentLengthSet && IsHtmlResponse ( ) )
41
41
{
42
- _context . Response . ContentLength = null ;
42
+ if ( ! _context . Response . HasStarted ) // can't set headers if response has already started
43
+ _context . Response . ContentLength = null ;
43
44
_isContentLengthSet = true ;
44
45
}
45
46
@@ -154,7 +155,7 @@ private bool IsHtmlResponse(bool forceReCheck = false)
154
155
// * text/html response
155
156
// * UTF-8 formatted (either explicitly or no charset defined)
156
157
_isHtmlResponse =
157
- _context . Response . ContentType != null &&
158
+ _context . Response . ContentType != null &&
158
159
_context . Response . ContentType . Contains ( "text/html" , StringComparison . OrdinalIgnoreCase ) &&
159
160
( _context . Response . ContentType . Contains ( "utf-8" , StringComparison . OrdinalIgnoreCase ) ||
160
161
! _context . Response . ContentType . Contains ( "charset=" , StringComparison . OrdinalIgnoreCase ) ) ;
@@ -170,7 +171,8 @@ private bool IsHtmlResponse(bool forceReCheck = false)
170
171
// and fail when it doesn't match if (_isHtmlResponse.Value)
171
172
if ( ! _isContentLengthSet && _context . Response . ContentLength != null )
172
173
{
173
- _context . Response . ContentLength = null ;
174
+ if ( ! _context . Response . HasStarted ) // can't set headers if response has already started
175
+ _context . Response . ContentLength = null ;
174
176
_isContentLengthSet = true ;
175
177
}
176
178
}
You can’t perform that action at this time.
0 commit comments