internal static void CleanupRequest(IRequest request)
{
var putObjectRequest = request.OriginalRequest as PutObjectRequest;
if (putObjectRequest != null)
{
if (putObjectRequest.InputStream != null
&& (!string.IsNullOrEmpty(putObjectRequest.FilePath) || putObjectRequest.AutoCloseStream))
{
putObjectRequest.InputStream.Dispose();
}
// Set the input stream to null since it was created during the request to represent the filepath or content body
if (!string.IsNullOrEmpty(putObjectRequest.FilePath) || !string.IsNullOrEmpty(putObjectRequest.ContentBody))
{
putObjectRequest.InputStream = null;
}
}
var uploadPartRequest = request.OriginalRequest as UploadPartRequest;
if (uploadPartRequest != null)
{
// FilePath was set, so we created the underlying stream, so we must close it
if (uploadPartRequest.IsSetFilePath() && uploadPartRequest.InputStream != null)
{
uploadPartRequest.InputStream.Dispose();
}
if (uploadPartRequest.IsSetFilePath())
uploadPartRequest.InputStream = null;
}
}
}