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

Another websocket fix #681

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Titanium.Web.Proxy/ExplicitClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
{
// todo: this is a hack, because Titanium does not support HTTP protocol changing currently
var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
noCache: true, cancellationToken: cancellationToken);
true, SslExtensions.Http2ProtocolAsList,
true, cancellationToken);

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

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

try
{
Expand Down Expand Up @@ -325,8 +325,8 @@ await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool,
}

var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
noCache: true, cancellationToken: cancellationToken);
true, SslExtensions.Http2ProtocolAsList,
true, cancellationToken);
try
{
#if NETSTANDARD2_1
Expand Down
3 changes: 2 additions & 1 deletion src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ internal async Task<TcpServerConnection> GetServerConnection(ProxyServer server,
customUpStreamProxy ?? (isHttps ? server.UpStreamHttpsProxy : server.UpStreamHttpProxy),
noCache, cancellationToken);
}

/// <summary>
/// Gets a TCP connection to server from connection pool.
/// </summary>
Expand Down Expand Up @@ -441,7 +442,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
connectRequest.Headers.AddHeader(HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password));
}

await stream.WriteRequestAsync(connectRequest, cancellationToken: cancellationToken);
await stream.WriteRequestAsync(connectRequest, cancellationToken);

var httpStatus = await stream.ReadResponseStatus(cancellationToken);

Expand Down
14 changes: 11 additions & 3 deletions src/Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,19 @@ private async Task<RetryResult> handleHttpSessionRequest(SessionEventArgs args,
// do not cache server connections for WebSockets
bool noCache = args.HttpClient.Request.UpgradeToWebSocket;

if (noCache)
{
serverConnection = null;
}

// a connection generator task with captured parameters via closure.
Func<Task<TcpServerConnection>> generator = () =>
tcpConnectionFactory.GetServerConnection(this, args, isConnect: false,
applicationProtocol: sslApplicationProtocol,
noCache: noCache, cancellationToken: cancellationToken);
tcpConnectionFactory.GetServerConnection(this,
args,
false,
sslApplicationProtocol,
noCache,
cancellationToken);

// for connection pool, retry fails until cache is exhausted.
return await retryPolicy<ServerConnectionException>().ExecuteAsync(async (connection) =>
Expand Down
6 changes: 3 additions & 3 deletions src/Titanium.Web.Proxy/TransparentClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConn
else
{
var connection = await tcpConnectionFactory.GetServerConnection(httpsHostName, endPoint.Port,
httpVersion: HttpHeader.VersionUnknown, isHttps: false, applicationProtocols: null,
isConnect: true, proxyServer: this, session:null, upStreamEndPoint: UpStreamEndPoint,
externalProxy: UpStreamHttpsProxy, noCache: true, cancellationToken: cancellationToken);
HttpHeader.VersionUnknown, false, null,
true, this, null, UpStreamEndPoint,
UpStreamHttpsProxy, true, cancellationToken);

try
{
Expand Down