Skip to content

Commit

Permalink
Set ResponseLength when Stream.CanSeek
Browse files Browse the repository at this point in the history
Don't attempt to write bytes when the bytesRead count is 0
  • Loading branch information
amaitland committed Apr 6, 2017
1 parent 440cc7a commit b357b73
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions CefSharp/ResourceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ public virtual Stream GetResponse(IResponse response, out long responseLength, o
else
{
//If no ResponseLength provided then attempt to infer the length
var memoryStream = Stream as MemoryStream;
if (memoryStream != null)
if (Stream != null && Stream.CanSeek)
{
responseLength = memoryStream.Length;
responseLength = Stream.Length;
}
}

Expand Down Expand Up @@ -212,6 +211,12 @@ bool IResourceHandler.ReadResponse(Stream dataOut, out int bytesRead, ICallback
var buffer = new byte[dataOut.Length];
bytesRead = Stream.Read(buffer, 0, buffer.Length);

//If bytesRead is 0 then no point attempting a write to dataOut
if(bytesRead == 0)
{
return false;
}

dataOut.Write(buffer, 0, buffer.Length);

return bytesRead > 0;
Expand Down

0 comments on commit b357b73

Please sign in to comment.