Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
{
e.HttpClient.Request.KeepBody = true;
await e.GetRequestBody();

if (item == SelectedSession)
{
await Dispatcher.InvokeAsync(selectedSessionChanged);
}
}
}

Expand All @@ -185,6 +190,10 @@ await Dispatcher.InvokeAsync(() =>
await e.GetResponseBody();

await Dispatcher.InvokeAsync(() => { item.Update(); });
if (item == SelectedSession)
{
await Dispatcher.InvokeAsync(selectedSessionChanged);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -450,7 +451,7 @@ public bool FillBuffer()
{
if (closed)
{
return false;
throw new Exception("Stream is already closed");
}

if (bufferLength > 0)
Expand All @@ -462,17 +463,23 @@ public bool FillBuffer()

bufferPos = 0;

int readBytes = baseStream.Read(streamBuffer, bufferLength, streamBuffer.Length - bufferLength);
bool result = readBytes > 0;
if (result)
bool result = false;
try
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
int readBytes = baseStream.Read(streamBuffer, bufferLength, streamBuffer.Length - bufferLength);
result = readBytes > 0;
if (result)
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
}
}
else
finally
{
closed = true;
throw new EndOfStreamException();
if (!result)
{
closed = true;
}
}

return result;
Expand All @@ -488,7 +495,7 @@ public async Task<bool> FillBufferAsync(CancellationToken cancellationToken = de
{
if (closed)
{
return false;
throw new Exception("Stream is already closed");
}

if (bufferLength > 0)
Expand All @@ -506,18 +513,23 @@ public async Task<bool> FillBufferAsync(CancellationToken cancellationToken = de

bufferPos = 0;

int readBytes = await baseStream.ReadAsync(streamBuffer, bufferLength, bytesToRead, cancellationToken);
bool result = readBytes > 0;
if (result)
bool result = false;
try
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
int readBytes = await baseStream.ReadAsync(streamBuffer, bufferLength, bytesToRead, cancellationToken);
result = readBytes > 0;
if (result)
{
OnDataRead(streamBuffer, bufferLength, readBytes);
bufferLength += readBytes;
}
}
else
finally
{
closed = true;

// do not throw exception here
if (!result)
{
closed = true;
}
}

return result;
Expand Down