Description
We have an API controller with the following action:
public async Task<IActionResult> UnpackZipFile()
{
try
{
using (var zip = new ZipArchive(this.Request.Body))
{
// Process ZIP file
}
return new OkResult();
}
catch (Exception ex)
{
this._logger.LogError(ex, "Could not unpack zip file");
return new BadRequestResult();
}
}
When Sentry's IncludeRequestPayload
is false
, the action behaves correctly. this.Request.Body
is of type Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream
in this case.
When Sentry's IncludeRequestPayload
is true
, the using part throws a System.NotSupportedException
exception, with the message "The content has not been fully buffered yet". This time this.Request.Body
is of type Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream
. Moreover, if the file is too large the log is not even sent to Sentry!
I suspect the Sentry middleware to wrap the request body stream in a rewindable FileBufferingReadStream
, but this stream is incompatible with the ZipArchive
constructor. I have no clue whether I'm doing something wrong in my original code, or if this is a bug the Sentry team should fix.
I am using ASP.NET Core 2.2 with IIS in-process hosting model and Sentry.AspNetCore NuGet in version 1.1.2.