Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 7eb8f29

Browse files
authored
Merge pull request #391 from justcoding121/develop
merge to beta
2 parents 5e1841f + a296120 commit 7eb8f29

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public MainWindow()
9090
//proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");
9191

9292
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true);
93-
94-
93+
9594
proxyServer.AddEndPoint(explicitEndPoint);
9695
//proxyServer.UpStreamHttpProxy = new ExternalProxy
9796
//{

Titanium.Web.Proxy/EventArguments/LimitedStream.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public LimitedStream(CustomBufferedStream baseStream, CustomBinaryReader baseRea
2222
this.baseStream = baseStream;
2323
this.baseReader = baseReader;
2424
this.isChunked = isChunked;
25-
bytesRemaining = isChunked ? 0 : contentLength;
25+
bytesRemaining = isChunked
26+
? 0
27+
: contentLength == -1
28+
? long.MaxValue
29+
: contentLength;
2630
}
2731

2832
private void GetNextChunk()
@@ -98,22 +102,31 @@ public override int Read(byte[] buffer, int offset, int count)
98102
int res = baseStream.Read(buffer, offset, toRead);
99103
bytesRemaining -= res;
100104

105+
if (res == 0)
106+
{
107+
bytesRemaining = -1;
108+
}
109+
101110
return res;
102111
}
103112

104113
public async Task Finish()
105114
{
106-
var buffer = BufferPool.GetBuffer(baseReader.Buffer.Length);
107-
try
115+
if (bytesRemaining != -1)
108116
{
109-
while (bytesRemaining != -1)
117+
var buffer = BufferPool.GetBuffer(baseReader.Buffer.Length);
118+
try
110119
{
111-
await ReadAsync(buffer, 0, buffer.Length);
120+
int res = await ReadAsync(buffer, 0, buffer.Length);
121+
if (res != 0)
122+
{
123+
throw new Exception("Data received after stream end");
124+
}
125+
}
126+
finally
127+
{
128+
BufferPool.ReturnBuffer(buffer);
112129
}
113-
}
114-
finally
115-
{
116-
BufferPool.ReturnBuffer(buffer);
117130
}
118131
}
119132

Titanium.Web.Proxy/Helpers/Tcp.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,8 @@ internal static async Task SendRawTap(Stream clientStream, Stream serverStream,
249249
internal static Task SendRaw(Stream clientStream, Stream serverStream, int bufferSize,
250250
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive, ExceptionHandler exceptionFunc)
251251
{
252-
#if NET45
253-
return SendRawApm(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc);
254-
#else
255-
// todo: Apm hangs in dotnet core
252+
// todo: fix APM mode
256253
return SendRawTap(clientStream, serverStream, bufferSize, onDataSend, onDataReceive, exceptionFunc);
257-
#endif
258254
}
259255
}
260256
}

0 commit comments

Comments
 (0)