Skip to content

Commit 0d8d4a6

Browse files
praves77keyur9
andauthored
#243026895: Create Owin Stream only if needed. (#100)
Co-authored-by: Keyur <keyur.kv@gmail.com>
1 parent ac5eec8 commit 0d8d4a6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Moesif.Middleware/NetFramework/MoesifMiddlewareNetFramework.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,21 @@ public void CreateStreamHelpers(IOwinContext httpContext, out StreamHelper outpu
266266
int parsedResContentLength = responseMaxBodySize - 1;
267267
GetContentLengthAndEncoding(resHeaders, parsedResContentLength, out parsedResContentLength); // Get the content-length from response header if possible.
268268
bool needToCreateStream = (logBody && parsedResContentLength <= responseMaxBodySize) ;
269+
bool needToCreateStreamOwin = needToCreateStream; // We do not create Owin Stream if MVC stream is success.
269270

270271
// Buffering mvc response
271272
HttpResponse httpResponse = HttpContext.Current?.Response;
272273
if (httpResponse != null && needToCreateStream)
273274
{
274275
outputCaptureMVC = new StreamHelper(httpResponse.Filter);
275276
httpResponse.Filter = outputCaptureMVC;
277+
278+
// Check if we need to create Owin stream
279+
needToCreateStreamOwin = (outputCaptureMVC == null || outputCaptureMVC.CopyStream.Length == 0);
276280
}
277281

278282
// Create stream to buffer Owin response
279-
if (needToCreateStream)
283+
if (needToCreateStreamOwin)
280284
{
281285
IOwinResponse owinResponse = httpContext.Response;
282286
outputCaptureOwin = new StreamHelper(owinResponse.Body);

0 commit comments

Comments
 (0)