mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
修复host解析失败问题
This commit is contained in:
parent
98eb26bd6d
commit
eb0d54e033
|
@ -28,7 +28,7 @@ namespace FastTunnel.Core.Dispatchers
|
|||
_fastTunnelServer = fastTunnelServer;
|
||||
}
|
||||
|
||||
static string pattern = @"[hH]ost:.+[\r\n]";
|
||||
static string pattern = @"[hH]ost:.+";
|
||||
|
||||
public void Dispatch(AsyncUserToken token, string words)
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ namespace FastTunnel.Core.Dispatchers
|
|||
MatchCollection collection = Regex.Matches(words, pattern);
|
||||
if (collection.Count == 0)
|
||||
{
|
||||
_logger.LogError($"Host异常:{words}");
|
||||
_logger.LogError($"【Host异常】:{words}");
|
||||
|
||||
// 返回错误页
|
||||
HandlerHostRequired(token.Socket);
|
||||
|
|
|
@ -57,7 +57,18 @@ namespace FastTunnel.Core.Listener
|
|||
|
||||
private bool handle(AsyncUserToken token, string words)
|
||||
{
|
||||
Message<JObject> msg = JsonConvert.DeserializeObject<Message<JObject>>(words);
|
||||
Message<JObject> msg;
|
||||
|
||||
try
|
||||
{
|
||||
msg = JsonConvert.DeserializeObject<Message<JObject>>(words);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, $"【异常的指令】{words}");
|
||||
token.Socket.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
IClientMessageHandler handler = null;
|
||||
switch (msg.MessageType)
|
||||
|
|
|
@ -47,8 +47,17 @@ namespace FastTunnel.Core.Listener
|
|||
|
||||
private bool handle(AsyncUserToken token, string words)
|
||||
{
|
||||
Console.WriteLine(words);
|
||||
_requestDispatcher.Dispatch(token, words);
|
||||
try
|
||||
{
|
||||
Console.WriteLine(words);
|
||||
_requestDispatcher.Dispatch(token, words);
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical(ex, $"【处理HTTP请求异常】{words}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace FastTunnel.Core.Server
|
|||
m_numConnections = numConnections;
|
||||
m_receiveBufferSize = receiveBufferSize;
|
||||
// allocate buffers such that the maximum number of sockets can have one outstanding read and
|
||||
//write posted to the socket simultaneously
|
||||
// write posted to the socket simultaneously
|
||||
m_bufferManager = new BufferManager(receiveBufferSize * numConnections * opsToPreAlloc,
|
||||
receiveBufferSize);
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@ using Microsoft.Extensions.Logging;
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.IO;
|
||||
|
||||
namespace FastTunnel.Core.Services
|
||||
{
|
||||
|
@ -19,6 +22,9 @@ namespace FastTunnel.Core.Services
|
|||
{
|
||||
_logger = logger;
|
||||
_fastTunnelClient = fastTunnelClient;
|
||||
|
||||
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
|
@ -34,5 +40,39 @@ namespace FastTunnel.Core.Services
|
|||
_logger.LogInformation("===== FastTunnel Client Stoping =====");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogError("【UnhandledException】" + e.ExceptionObject);
|
||||
_logger.LogError("【UnhandledException】" + JsonConvert.SerializeObject(e.ExceptionObject));
|
||||
var type = e.ExceptionObject.GetType();
|
||||
_logger.LogError("ExceptionObject GetType " + type);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void CurrentDomain_FirstChanceException(object sender, FirstChanceExceptionEventArgs e)
|
||||
{
|
||||
if (e.Exception is DirectoryNotFoundException)
|
||||
{
|
||||
// nlog第一次找不到文件的错误,跳过
|
||||
}
|
||||
else if (e.Exception is PlatformNotSupportedException)
|
||||
{
|
||||
// log4net
|
||||
}
|
||||
else if (e.Exception is IOException && e.Exception.Source == "System.Net.Security")
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError(e.Exception, "【FirstChanceException】");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,10 @@ namespace FastTunnel.Core.Services
|
|||
{
|
||||
// nlog第一次找不到文件的错误,跳过
|
||||
}
|
||||
else if (e.Exception is PlatformNotSupportedException)
|
||||
{
|
||||
// log4net
|
||||
}
|
||||
else if (e.Exception is IOException && e.Exception.Source == "System.Net.Security")
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user