Skip to content

Commit

Permalink
#243026895: Create Owin Stream only if needed. (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: Keyur <keyur.kv@gmail.com>
  • Loading branch information
praves77 and keyur9 authored Nov 22, 2024
1 parent ac5eec8 commit 0d8d4a6
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,21 @@ public void CreateStreamHelpers(IOwinContext httpContext, out StreamHelper outpu
int parsedResContentLength = responseMaxBodySize - 1;
GetContentLengthAndEncoding(resHeaders, parsedResContentLength, out parsedResContentLength); // Get the content-length from response header if possible.
bool needToCreateStream = (logBody && parsedResContentLength <= responseMaxBodySize) ;
bool needToCreateStreamOwin = needToCreateStream; // We do not create Owin Stream if MVC stream is success.

// Buffering mvc response
HttpResponse httpResponse = HttpContext.Current?.Response;
if (httpResponse != null && needToCreateStream)
{
outputCaptureMVC = new StreamHelper(httpResponse.Filter);
httpResponse.Filter = outputCaptureMVC;

// Check if we need to create Owin stream
needToCreateStreamOwin = (outputCaptureMVC == null || outputCaptureMVC.CopyStream.Length == 0);
}

// Create stream to buffer Owin response
if (needToCreateStream)
if (needToCreateStreamOwin)
{
IOwinResponse owinResponse = httpContext.Response;
outputCaptureOwin = new StreamHelper(owinResponse.Body);
Expand Down

0 comments on commit 0d8d4a6

Please sign in to comment.