Skip to content

Commit

Permalink
update console test
Browse files Browse the repository at this point in the history
  • Loading branch information
tqk2811 committed Apr 1, 2024
1 parent 3a46607 commit ae36574
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
30 changes: 20 additions & 10 deletions src/ConsoleTest/DebugTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using TqkLibrary.Proxy.Authentications;
using TqkLibrary.Proxy.Handlers;
using TqkLibrary.Proxy.Interfaces;
using TqkLibrary.Proxy.ProxyServers;
Expand All @@ -13,22 +14,31 @@ namespace ConsoleTest
{
internal static class DebugTest
{
class MyBaseProxyServerHandler : BaseProxyServerHandler
{
readonly HttpProxyAuthentication _httpProxyAuthentication;
public MyBaseProxyServerHandler(HttpProxyAuthentication httpProxyAuthentication, IProxySource proxySource) : base(proxySource)
{
_httpProxyAuthentication = httpProxyAuthentication;
}
public override Task<bool> IsAcceptUserAsync(IUserInfo userInfo, CancellationToken cancellationToken = default)
{
if (userInfo.Authentication is HttpProxyAuthentication httpProxyAuthentication)
{
return Task.FromResult(httpProxyAuthentication.Equals(_httpProxyAuthentication));
}
return base.IsAcceptUserAsync(userInfo, cancellationToken);
}
}
public static async Task Test()
{
//const string address = "127.0.0.1:13566";
const string address = "[::1]:13566";
IProxySource proxySource = new LocalProxySource();


CredentialCache credentialCache = new CredentialCache();
NetworkCredential networkCredential = new NetworkCredential("admin", "admin");
credentialCache.Add(new Uri($"http://{address}"), "Basic", networkCredential);

HttpAuthenticationProxyServerHandler handler = new HttpAuthenticationProxyServerHandler(proxySource);
handler.WithAuthentications(networkCredential);

HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse(address), handler);
httpProxyServer.StartListen();
ProxyServer proxyServer = new ProxyServer(IPEndPoint.Parse(address), new MyBaseProxyServerHandler(networkCredential, proxySource));
proxyServer.StartListen();

using HttpClientHandler httpClientHandler = new HttpClientHandler()
{
Expand Down Expand Up @@ -81,7 +91,7 @@ public static async Task Test()


Console.ReadLine();
httpProxyServer.StopListen();
proxyServer.StopListen();

Console.ReadLine();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ConsoleTest/ProxyWraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static async Task RunAsync()

//ipEndPoint = new IPEndPoint(IPAddress.Any, 0);

using var server = new HttpProxyServer(ipEndPoint, GetProxySource());
using var server = new ProxyServer(ipEndPoint, GetProxySource());
server.StartListen();
Console.WriteLine($"Listening {server.IPEndPoint}");
Console.ReadLine();
Expand Down
12 changes: 6 additions & 6 deletions src/ConsoleTest/RealTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public static void HttpProxyServerTest()
//IProxySource proxySource = new LocalProxySource();
//IProxySource proxySource = new HttpProxySource(new Uri("http://103.178.231.186:10003"));
IProxySource proxySource = new HttpProxySource(new Uri("http://svhn1.proxyno1.com:41352"));
HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse(address), proxySource);
httpProxyServer.StartListen();
ProxyServer proxyServer = new ProxyServer(IPEndPoint.Parse(address), proxySource);
proxyServer.StartListen();
Console.WriteLine("server started");
Console.ReadLine();
//httpProxyServer.ChangeSource(new HttpProxySource(new Uri("http://103.178.231.186:10003")), true);
Console.ReadLine();
httpProxyServer.StopListen();
proxyServer.StopListen();
Console.ReadLine();
}

Expand All @@ -49,13 +49,13 @@ public static void Socks4ProxySourceTest()


IProxySource proxySource = new Socks4ProxySource(IPEndPoint.Parse("212.213.132.5:31632"));//địa chỉ sock4
HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse("127.0.0.1:13566"), proxySource);//địa chỉ http proxy host lại
ProxyServer proxyServer = new ProxyServer(IPEndPoint.Parse("127.0.0.1:13566"), proxySource);//địa chỉ http proxy host lại

httpProxyServer.StartListen();//xài
proxyServer.StartListen();//xài

//code..... dùng proxy 127.0.0.1:13566

httpProxyServer.StopListen();//xài xong nhớ tắt
proxyServer.StopListen();//xài xong nhớ tắt


Console.ReadLine();
Expand Down

0 comments on commit ae36574

Please sign in to comment.