Skip to content

Commit

Permalink
HttpProxySource.ConnectTunnel try catch InitConnectSourceFailedExcept…
Browse files Browse the repository at this point in the history
…ion return 503
  • Loading branch information
tqk2811 committed Jul 18, 2024
1 parent 4bd4beb commit b125b44
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/TqkLibrary.Proxy/ProxyServers/HttpProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Text;
using TqkLibrary.Proxy.Authentications;
using TqkLibrary.Proxy.Exceptions;
using TqkLibrary.Proxy.Helpers;
using TqkLibrary.Proxy.Interfaces;
using TqkLibrary.Proxy.StreamHeplers;
Expand Down Expand Up @@ -82,15 +83,23 @@ public async Task ProxyWorkAsync(
{
IProxySource proxySource = await proxyServerHandler.GetProxySourceAsync(_client_HeaderParse.Uri, userInfo, cancellationToken);
using IConnectSource connectSource = proxySource.GetConnectSource();
await connectSource.ConnectAsync(_client_HeaderParse.Uri, _cancellationToken);
using Stream source_stream = await connectSource.GetStreamAsync();
if ("CONNECT".Equals(_client_HeaderParse.Method, StringComparison.OrdinalIgnoreCase))
try
{
should_continue = await _HttpsTransfer(source_stream, userInfo);
await connectSource.ConnectAsync(_client_HeaderParse.Uri, _cancellationToken);
using Stream source_stream = await connectSource.GetStreamAsync();
if ("CONNECT".Equals(_client_HeaderParse.Method, StringComparison.OrdinalIgnoreCase))
{
should_continue = await _HttpsTransfer(source_stream, userInfo);
}
else
{
should_continue = await _HttpTransfer(source_stream, userInfo);
}
}
else
catch (InitConnectSourceFailedException ex)
{
should_continue = await _HttpTransfer(source_stream, userInfo);
_logger?.LogInformation(ex, "InitConnectSourceFailedException");
await _WriteResponse((int)HttpStatusCode.ServiceUnavailable, "Service Unavailable", true);
}
}
else
Expand Down

0 comments on commit b125b44

Please sign in to comment.