Skip to content

Commit

Permalink
fix: reset response stream only if seekable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpop-zengenti committed May 8, 2024
1 parent 70fcf87 commit d81a8bb
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ public EndpointResponse(

public PageletPerformanceData? PageletPerformanceData { get; }

public Stream? ToStream(bool resetPosition = false)
public Stream? ToStream(bool resetPositionIfSeekable = false)
{
if (StreamContent != null)
{
if (resetPosition)
if (!resetPositionIfSeekable)
{
StreamContent.Position = 0;
return StreamContent;
}

return StreamContent;
if (StreamContent.CanSeek)
{
StreamContent.Position = 0;
return StreamContent;
}
}

if (string.IsNullOrWhiteSpace(StringContent))
Expand All @@ -69,7 +73,7 @@ public EndpointResponse(
var writer = new StreamWriter(stream, leaveOpen: true);
writer.Write(StringContent);
writer.Flush();
if (resetPosition)
if (resetPositionIfSeekable && stream.CanSeek)
{
stream.Position = 0;
}
Expand Down

0 comments on commit d81a8bb

Please sign in to comment.