diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs index e62a9b5c6..7293df085 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs @@ -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); + } } } @@ -185,6 +190,10 @@ await Dispatcher.InvokeAsync(() => await e.GetResponseBody(); await Dispatcher.InvokeAsync(() => { item.Update(); }); + if (item == SelectedSession) + { + await Dispatcher.InvokeAsync(selectedSessionChanged); + } } } } diff --git a/src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs b/src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs index e32bcaef5..36f03d383 100644 --- a/src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs +++ b/src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs @@ -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; @@ -450,7 +451,7 @@ public bool FillBuffer() { if (closed) { - return false; + throw new Exception("Stream is already closed"); } if (bufferLength > 0) @@ -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; @@ -488,7 +495,7 @@ public async Task FillBufferAsync(CancellationToken cancellationToken = de { if (closed) { - return false; + throw new Exception("Stream is already closed"); } if (bufferLength > 0) @@ -506,18 +513,23 @@ public async Task 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;