Unverified Commit 7eb8f297 authored by honfika's avatar honfika Committed by GitHub

Merge pull request #391 from justcoding121/develop

merge to beta
parents 5e1841ff a2961205
...@@ -90,8 +90,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -90,8 +90,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
//proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword"); //proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true); var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true);
proxyServer.AddEndPoint(explicitEndPoint); proxyServer.AddEndPoint(explicitEndPoint);
//proxyServer.UpStreamHttpProxy = new ExternalProxy //proxyServer.UpStreamHttpProxy = new ExternalProxy
//{ //{
......
...@@ -22,7 +22,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -22,7 +22,11 @@ namespace Titanium.Web.Proxy.EventArguments
this.baseStream = baseStream; this.baseStream = baseStream;
this.baseReader = baseReader; this.baseReader = baseReader;
this.isChunked = isChunked; this.isChunked = isChunked;
bytesRemaining = isChunked ? 0 : contentLength; bytesRemaining = isChunked
? 0
: contentLength == -1
? long.MaxValue
: contentLength;
} }
private void GetNextChunk() private void GetNextChunk()
...@@ -98,22 +102,31 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -98,22 +102,31 @@ namespace Titanium.Web.Proxy.EventArguments
int res = baseStream.Read(buffer, offset, toRead); int res = baseStream.Read(buffer, offset, toRead);
bytesRemaining -= res; bytesRemaining -= res;
if (res == 0)
{
bytesRemaining = -1;
}
return res; return res;
} }
public async Task Finish() public async Task Finish()
{ {
var buffer = BufferPool.GetBuffer(baseReader.Buffer.Length); if (bytesRemaining != -1)
try
{ {
while (bytesRemaining != -1) var buffer = BufferPool.GetBuffer(baseReader.Buffer.Length);
try
{ {
await ReadAsync(buffer, 0, buffer.Length); int res = await ReadAsync(buffer, 0, buffer.Length);
if (res != 0)
{
throw new Exception("Data received after stream end");
}
}
finally
{
BufferPool.ReturnBuffer(buffer);
} }
}
finally
{
BufferPool.ReturnBuffer(buffer);
} }
} }
......
...@@ -249,12 +249,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -249,12 +249,8 @@ namespace Titanium.Web.Proxy.Helpers
internal static Task SendRaw(Stream clientStream, Stream serverStream, int bufferSize, internal static Task SendRaw(Stream clientStream, Stream serverStream, int bufferSize,
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive, ExceptionHandler exceptionFunc) Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive, ExceptionHandler exceptionFunc)
{ {
#if NET45 // todo: fix APM mode
return SendRawApm(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc);
#else
// todo: Apm hangs in dotnet core
return SendRawTap(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc); 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