Commit a2961205 authored by Honfika's avatar Honfika

fix

parent fa0d9f2a
......@@ -91,7 +91,6 @@ namespace Titanium.Web.Proxy.Examples.Wpf
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true);
proxyServer.AddEndPoint(explicitEndPoint);
//proxyServer.UpStreamHttpProxy = new ExternalProxy
//{
......
......@@ -22,7 +22,11 @@ namespace Titanium.Web.Proxy.EventArguments
this.baseStream = baseStream;
this.baseReader = baseReader;
this.isChunked = isChunked;
bytesRemaining = isChunked ? 0 : contentLength;
bytesRemaining = isChunked
? 0
: contentLength == -1
? long.MaxValue
: contentLength;
}
private void GetNextChunk()
......@@ -98,17 +102,25 @@ namespace Titanium.Web.Proxy.EventArguments
int res = baseStream.Read(buffer, offset, toRead);
bytesRemaining -= res;
if (res == 0)
{
bytesRemaining = -1;
}
return res;
}
public async Task Finish()
{
if (bytesRemaining != -1)
{
var buffer = BufferPool.GetBuffer(baseReader.Buffer.Length);
try
{
while (bytesRemaining != -1)
int res = await ReadAsync(buffer, 0, buffer.Length);
if (res != 0)
{
await ReadAsync(buffer, 0, buffer.Length);
throw new Exception("Data received after stream end");
}
}
finally
......@@ -116,6 +128,7 @@ namespace Titanium.Web.Proxy.EventArguments
BufferPool.ReturnBuffer(buffer);
}
}
}
public override void Write(byte[] buffer, int offset, int count)
{
......
......@@ -249,12 +249,8 @@ namespace Titanium.Web.Proxy.Helpers
internal static Task SendRaw(Stream clientStream, Stream serverStream, int bufferSize,
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive, ExceptionHandler exceptionFunc)
{
#if NET45
return SendRawApm(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc);
#else
// todo: Apm hangs in dotnet core
// todo: fix APM mode
return SendRawTap(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc);
#endif
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment