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

Commit 35a4890

Browse files
authored
Merge pull request #681 from justcoding121/master
Another websocket fix
2 parents b584af9 + 9e02fc7 commit 35a4890

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/Titanium.Web.Proxy/ExplicitClientHandler.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
140140
{
141141
// todo: this is a hack, because Titanium does not support HTTP protocol changing currently
142142
var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
143-
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
144-
noCache: true, cancellationToken: cancellationToken);
143+
true, SslExtensions.Http2ProtocolAsList,
144+
true, cancellationToken);
145145

146146
http2Supported = connection.NegotiatedApplicationProtocol ==
147147
SslApplicationProtocol.Http2;
@@ -170,8 +170,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
170170
// don't pass cancellation token here
171171
// it could cause floating server connections when client exits
172172
prefetchConnectionTask = tcpConnectionFactory.GetServerConnection(this, connectArgs,
173-
isConnect: true, applicationProtocols: null, noCache: false,
174-
cancellationToken: CancellationToken.None);
173+
true, null, false,
174+
CancellationToken.None);
175175
}
176176
}
177177

@@ -253,8 +253,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
253253
// If we detected that client tunnel CONNECTs without SSL by checking for empty client hello then
254254
// this connection should not be HTTPS.
255255
var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
256-
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
257-
noCache: true, cancellationToken: cancellationToken);
256+
true, SslExtensions.Http2ProtocolAsList,
257+
true, cancellationToken);
258258

259259
try
260260
{
@@ -325,8 +325,8 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
325325
}
326326

327327
var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
328-
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
329-
noCache: true, cancellationToken: cancellationToken);
328+
true, SslExtensions.Http2ProtocolAsList,
329+
true, cancellationToken);
330330
try
331331
{
332332
#if NETSTANDARD2_1

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ internal async Task<TcpServerConnection> GetServerConnection(ProxyServer server,
190190
customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy),
191191
noCache, cancellationToken);
192192
}
193+
193194
/// <summary>
194195
/// Gets a TCP connection to server from connection pool.
195196
/// </summary>
@@ -441,7 +442,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
441442
connectRequest.Headers.AddHeader(HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password));
442443
}
443444

444-
await stream.WriteRequestAsync(connectRequest, cancellationToken: cancellationToken);
445+
await stream.WriteRequestAsync(connectRequest, cancellationToken);
445446

446447
var httpStatus = await stream.ReadResponseStatus(cancellationToken);
447448

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,19 @@ private async Task<RetryResult> handleHttpSessionRequest(SessionEventArgs args,
261261
// do not cache server connections for WebSockets
262262
bool noCache = args.HttpClient.Request.UpgradeToWebSocket;
263263

264+
if (noCache)
265+
{
266+
serverConnection = null;
267+
}
268+
264269
// a connection generator task with captured parameters via closure.
265270
Func<Task<TcpServerConnection>> generator = () =>
266-
tcpConnectionFactory.GetServerConnection(this, args, isConnect: false,
267-
applicationProtocol: sslApplicationProtocol,
268-
noCache: noCache, cancellationToken: cancellationToken);
271+
tcpConnectionFactory.GetServerConnection(this,
272+
args,
273+
false,
274+
sslApplicationProtocol,
275+
noCache,
276+
cancellationToken);
269277

270278
// for connection pool, retry fails until cache is exhausted.
271279
return await retryPolicy<ServerConnectionException>().ExecuteAsync(async (connection) =>

src/Titanium.Web.Proxy/TransparentClientHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConn
8989
else
9090
{
9191
var connection = await tcpConnectionFactory.GetServerConnection(httpsHostName, endPoint.Port,
92-
httpVersion: HttpHeader.VersionUnknown, isHttps: false, applicationProtocols: null,
93-
isConnect: true, proxyServer: this, session:null, upStreamEndPoint: UpStreamEndPoint,
94-
externalProxy: UpStreamHttpsProxy, noCache: true, cancellationToken: cancellationToken);
92+
HttpHeader.VersionUnknown, false, null,
93+
true, this, null, UpStreamEndPoint,
94+
UpStreamHttpsProxy, true, cancellationToken);
9595

9696
try
9797
{

0 commit comments

Comments
 (0)