diff --git a/Mime/HttpMimeContext.cs b/Mime/HttpMimeContext.cs index ddb1b58..50e363a 100644 --- a/Mime/HttpMimeContext.cs +++ b/Mime/HttpMimeContext.cs @@ -86,8 +86,91 @@ namespace UMC.ITME _request.Dispose(); } + WriteLog(); } + void WriteLog() + { + var logSetting = LogSetting.Instance(); + if (logSetting.IsWriter) + { + if (_logs.Length == 0) + { + _logs = System.Buffers.ArrayPool.Shared.Rent(25); + _logs[0] = "ITME"; + _logSize = 1; + + } + + + // IsLog = true; + int logSize = _logSize; + + if (this.Token != null) + { + var username = this.Token.Username; + if (String.IsNullOrEmpty(username) || String.Equals(username, "?")) + { + username = $"G:{UMC.Data.Utility.IntParse((this.Token.UserId ?? this.Token.Device).Value)}"; + } + _logs[logSize++] = "Username"; + _logs[logSize++] = username; + } + + + var duration = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - _request.startTime; + + _logs[logSize++] = "Address"; + _logs[logSize++] = this.UserHostAddress; + + _logs[logSize++] = "Server"; + _logs[logSize++] = this.Server; + + _logs[logSize++] = "UserAgent"; + _logs[logSize++] = this.UserAgent; + + _logs[logSize++] = "Path"; + _logs[logSize++] = this.RawUrl; + + _logs[logSize++] = "Duration"; + _logs[logSize++] = duration.ToString(); + + _logs[logSize++] = "Status"; + _logs[logSize++] = this.StatusCode.ToString(); + + if (this.UrlReferrer != null) + { + _logs[logSize++] = "Referrer"; + _logs[logSize++] = this.UrlReferrer.AbsoluteUri; + + } + logSetting.Write(_logs, 0, logSize); + System.Buffers.ArrayPool.Shared.Return(_logs); + + } + } + int _logSize = 0; + String[] _logs = Array.Empty(); + public void WriteLog(String[] logs, int size) + { + if (_logs.Length > 0) + { + System.Buffers.ArrayPool.Shared.Return(_logs); + } + this._logSize = size; + this._logs = logs; + } + // public void WriteLog(String[] logs, int size) + // { + // var logSetting = LogSetting.Instance(); + // if (logSetting.IsWriter) + // { + // } + // } + // public bool IsLog + // { + // get; set; + // } public override void Error(Exception ex) { this.Output.Flush(); @@ -99,6 +182,7 @@ namespace UMC.ITME } _request._context.Dispose(); _request.Dispose(); + WriteLog(); } public override void ReadAsForm(Action action) @@ -137,6 +221,10 @@ namespace UMC.ITME _request.Dispose(); } + else + { + WriteLog(); + } } public override int StatusCode { diff --git a/Mime/HttpMimeRequest.cs b/Mime/HttpMimeRequest.cs index e135269..2fe0699 100644 --- a/Mime/HttpMimeRequest.cs +++ b/Mime/HttpMimeRequest.cs @@ -29,12 +29,14 @@ namespace UMC.ITME } NameValueCollection _Cookies = new NameValueCollection(); internal HttpMime _context; + internal long startTime; public HttpMimeRequest(HttpMime context) { _context = context; + this.startTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); this._remoteIpAddress = context.RemoteIpAddress; - +// (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - StartTime) } public string HttpMethod { diff --git a/Mime/HttpMimeSocket.cs b/Mime/HttpMimeSocket.cs index 497c234..b66cce5 100644 --- a/Mime/HttpMimeSocket.cs +++ b/Mime/HttpMimeSocket.cs @@ -96,7 +96,6 @@ namespace UMC.ITME { if (IsHeader) { - IsHeader = true; if (this._data[0] == 0x1) { try @@ -104,9 +103,9 @@ namespace UMC.ITME Subscribe(this._data, e.Offset + 1, e.BytesTransferred - 1); // _socket = null; } - catch //(Exception ex) + catch (Exception ex) { - + Utility.Error("Subscribe", ex.ToString()); } finally { @@ -114,6 +113,7 @@ namespace UMC.ITME } return false; } + IsHeader = true; } this.Request = new HttpMimeRequest(this); } @@ -155,9 +155,10 @@ namespace UMC.ITME void Subscribe(byte[] header, int offset, int size) { var headers = new NameValueCollection(); - var ps = System.Text.Encoding.UTF8.GetString(header, offset, size).Split("\r\n"); + var ps = System.Text.Encoding.UTF8.GetString(header, offset, size).Split("\r\n", StringSplitOptions.RemoveEmptyEntries); foreach (var s in ps) { + var vi = s.IndexOf(':'); var key = s.Substring(0, vi); var value = s.Substring(vi + 2); @@ -176,7 +177,7 @@ namespace UMC.ITME length += $"UMC-Publisher-Key: {HttpMimeServier.Server}\r\n".WriteBytes(header, length); length += "Server: ITME\r\n\r\n".WriteBytes(header, length); _socket.Send(header, 0, length, SocketFlags.None); - _subscribe.Publish(); + _socket = null; } else diff --git a/Proxy/HttpProxy.cs b/Proxy/HttpProxy.cs index 9557dbb..27d94f1 100644 --- a/Proxy/HttpProxy.cs +++ b/Proxy/HttpProxy.cs @@ -12,6 +12,7 @@ using System.Security.Cryptography; using System.Collections.Specialized; using System.IO.Compression; using Microsoft.VisualBasic; +using System.Runtime.CompilerServices; namespace UMC.ITME { @@ -108,7 +109,7 @@ namespace UMC.ITME this.RawUrl = ReplaceRawUrl(this.RawUrl); - this.StartTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); + // this.StartTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); } private HttpProxy(HttpProxy proxy, SiteConfig siteConfig) { @@ -846,7 +847,7 @@ namespace UMC.ITME int statusCode = Convert.ToInt32(res.StatusCode); if (statusCode >= 500) { - LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, 0, res.Headers, this._AttachmentFile); + LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, res.Headers, this._AttachmentFile); } @@ -971,7 +972,7 @@ namespace UMC.ITME int statusCode = Convert.ToInt32(res.StatusCode); if (statusCode >= 500) { - LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, 0, res.Headers, this._AttachmentFile); + LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, res.Headers, this._AttachmentFile); } if (res.StatusCode != HttpStatusCode.OK) @@ -2230,7 +2231,7 @@ namespace UMC.ITME int statusCode = Convert.ToInt32(httpResponse.StatusCode); if (statusCode >= 500) { - LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, 0, httpResponse.Headers, _AttachmentFile); + LogWrite(this.Context, this.Site, statusCode, String.Format("{0} {1}", Method, getUrl.PathAndQuery), this.SiteCookie.Account, httpResponse.Headers, _AttachmentFile); } if (this.IsLog == true) @@ -2838,41 +2839,60 @@ namespace UMC.ITME } - public static void LogWrite(NetContext context, SiteConfig config, int statusCode, String pathAndQuery, string account, int duration, NameValueCollection reHeaders, String attachmentFile) + public static void LogWrite(NetContext context, SiteConfig config, string account, NameValueCollection reHeaders, String attachmentFile) { + var logSetting = LogSetting.Instance(); if (logSetting.IsWriter) { - var webMeta = new WebMeta(); + var logs = System.Buffers.ArrayPool.Shared.Rent(config.LogConf.Cookies.Length + config.LogConf.Headers.Length + config.LogConf.ResHeaders.Length + 24); + int logSize = 1; + logs[0] = config.Root; + if (String.IsNullOrEmpty(account) == false) { - webMeta.Put("Account", account); - } - var time = (int)((UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - duration) / 1000); - if (context.UrlReferrer != null) - { - webMeta.Put("Referrer", context.UrlReferrer.AbsoluteUri); + logs[logSize++] = "Account"; + logs[logSize++] = account; } if (String.IsNullOrEmpty(attachmentFile) == false) { - webMeta.Put("Attachment", attachmentFile); + logs[logSize++] = "Attachment"; + logs[logSize++] = attachmentFile; + } foreach (var u in config.LogConf.Cookies) { - webMeta[u] = context.Cookies[u]; + logs[logSize++] = u; + logs[logSize++] = context.Cookies[u]; + } foreach (var u in config.LogConf.Headers) { - webMeta[u] = context.Headers[u]; + logs[logSize++] = u; + logs[logSize++] = context.Headers[u]; } if (reHeaders != null) { foreach (var u in config.LogConf.ResHeaders) { - webMeta[u] = reHeaders[u]; + logs[logSize++] = u; + logs[logSize++] = reHeaders[u]; } } + HttpMimeContext httpMimeContext = (HttpMimeContext)context; + httpMimeContext.WriteLog(logs, logSize); + } + } + public static void LogWrite(NetContext context, SiteConfig config, int statusCode, String pathAndQuery, string account, NameValueCollection reHeaders, String attachmentFile) + { + var logSetting = LogSetting.Instance(); + if (logSetting.IsWriter) + { + var logs = System.Buffers.ArrayPool.Shared.Rent(config.LogConf.Cookies.Length + config.LogConf.Headers.Length + config.LogConf.ResHeaders.Length + 24); + int logSize = 1; + logs[0] = config.Root; + if (context.Token != null) { @@ -2881,16 +2901,64 @@ namespace UMC.ITME { username = $"G:{UMC.Data.Utility.IntParse((context.Token.UserId ?? context.Token.Device).Value)}"; } - webMeta.Put("Username", username); + logs[logSize++] = "Username"; + logs[logSize++] = username; } - webMeta.Put("Address", context.UserHostAddress).Put("Server", context.Server).Put("UserAgent", context.UserAgent) - .Put("Path", pathAndQuery) - .Put("Duration", duration) - .Put("Site", config.Root) - .Put("Time", time) - .Put("Status", statusCode); - logSetting.Write(webMeta); + + + logs[logSize++] = "Address"; + logs[logSize++] = context.UserHostAddress; + + logs[logSize++] = "Server"; + logs[logSize++] = context.Server; + + logs[logSize++] = "UserAgent"; + logs[logSize++] = context.UserAgent; + + logs[logSize++] = "Path"; + logs[logSize++] = pathAndQuery; + + + logs[logSize++] = "Status"; + logs[logSize++] = statusCode.ToString(); + + logs[logSize++] = "Referrer"; + logs[logSize++] = context.UrlReferrer?.AbsoluteUri; + + if (String.IsNullOrEmpty(account) == false) + { + logs[logSize++] = "Account"; + logs[logSize++] = account; + } + if (String.IsNullOrEmpty(attachmentFile) == false) + { + logs[logSize++] = "Attachment"; + logs[logSize++] = attachmentFile; + + } + foreach (var u in config.LogConf.Cookies) + { + logs[logSize++] = u; + logs[logSize++] = context.Cookies[u]; + + } + + foreach (var u in config.LogConf.Headers) + { + logs[logSize++] = u; + logs[logSize++] = context.Headers[u]; + } + if (reHeaders != null) + { + foreach (var u in config.LogConf.ResHeaders) + { + logs[logSize++] = u; + logs[logSize++] = reHeaders[u]; + } + } + logSetting.Write(logs, 0, logSize); + System.Buffers.ArrayPool.Shared.Return(logs); } } @@ -3153,12 +3221,13 @@ namespace UMC.ITME } UMC.Security.Identity User; - long StartTime; + // long StartTime; public void ProcessEnd() { + LogWrite(this.Context, this.Site, this.SiteCookie.Account, m_HttpHeaders, _AttachmentFile); - LogWrite(this.Context, this.Site, this.Context.StatusCode, String.Format("{0} {1}", Context.HttpMethod, this.RawUrl), this.SiteCookie.Account, (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - StartTime), m_HttpHeaders, _AttachmentFile); + // LogWrite(this.Context, this.Site, this.Context.StatusCode, String.Format("{0} {1}", Context.HttpMethod, this.RawUrl), this.SiteCookie.Account, (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - StartTime), m_HttpHeaders, _AttachmentFile); this.SaveCookie(); if (this.IsLog && User.IsAuthenticated) @@ -3185,7 +3254,7 @@ namespace UMC.ITME AuthBridge(this.Context.Headers); } internal void AuthBridge(NameValueCollection heaers) - { + { var user = this.User; switch (this.Site.Site.UserModel) diff --git a/Proxy/LogSetting.cs b/Proxy/LogSetting.cs index d8a32d0..5d42609 100644 --- a/Proxy/LogSetting.cs +++ b/Proxy/LogSetting.cs @@ -3,6 +3,9 @@ using System.Collections.Concurrent; using UMC.Data; using System.Text; using System.Net.Sockets; +using System.Net.NetworkInformation; +using UMC.Net; +using System.Threading.Tasks; namespace UMC.ITME { @@ -10,70 +13,30 @@ namespace UMC.ITME class LogSetting : UMC.Data.DataProvider { - UdpClient client; - class UdpWriter : System.IO.TextWriter + static int Mtu = Int32.MaxValue; + static LogSetting() { - byte[] _buffers; - short _bufferSize, _seq = 0; - UdpClient client; - int hashcode; - public override Encoding Encoding => Encoding.UTF8; - public UdpWriter(UdpClient client) - { - this.client = client; - this.hashcode = Guid.NewGuid().GetHashCode(); - _buffers = System.Buffers.ArrayPool.Shared.Rent(548); - } - public override void Flush() - { + // 获取所有网络接口 + NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); - BitConverter.TryWriteBytes(_buffers, hashcode); - BitConverter.TryWriteBytes(_buffers.AsSpan(4), -_seq); - _seq = 0; - BitConverter.TryWriteBytes(_buffers.AsSpan(6), _bufferSize); - this.client.Send(_buffers, _bufferSize + 8); - _bufferSize = 0; - this.hashcode = Guid.NewGuid().GetHashCode(); - - } - public override void Close() + foreach (NetworkInterface networkInterface in networkInterfaces) { - base.Dispose(true); - } - protected override void Dispose(bool disposing) - { - if (_buffers != null) + // 确保网络接口已启用并支持IPv4 + if (networkInterface.OperationalStatus == OperationalStatus.Up && + networkInterface.Supports(NetworkInterfaceComponent.IPv4)) { - System.Buffers.ArrayPool.Shared.Return(_buffers); + // 获取并打印MTU + int mtu = networkInterface.GetIPProperties().GetIPv4Properties().Mtu; + if (mtu < Mtu) + { + Mtu = mtu; + } } - _buffers = null; - - base.Dispose(disposing); - } - char[] _chars = new char[1]; - - void Send() - { - BitConverter.TryWriteBytes(_buffers, hashcode); - BitConverter.TryWriteBytes(_buffers.AsSpan(4), _seq); - _seq++; - BitConverter.TryWriteBytes(_buffers.AsSpan(6), _bufferSize); - this.client.Send(_buffers, _bufferSize + 8); - _bufferSize = 0; } - public override void Write(char value) - { - if (_bufferSize + 6 > 540) - { - Send(); - _bufferSize = 0; - } - _chars[0] = value; - _bufferSize += Convert.ToInt16(Encoding.UTF8.GetBytes(_chars, 0, 1, _buffers, _bufferSize + 8)); - } } + UdpClient client; public static LogSetting Instance() { @@ -103,47 +66,53 @@ namespace UMC.ITME var host = provider["host"]; if (String.IsNullOrEmpty(host) == false) { - var port = Utility.IntParse(provider["port"], 5188); - _isWriter = true; + var port = Utility.IntParse(provider["port"], 514); + _isWriter = Mtu > 512; this.client = new UdpClient(host, port); } else { + this.client?.Dispose(); _isWriter = false; } } else { + this.client?.Dispose(); _isWriter = false; } - foreach (var l in _logMetas) - { - l.Dispose(); - } - _logMetas.Clear(); } - - ConcurrentQueue _logMetas = new ConcurrentQueue(); - - public virtual void Write(Web.WebMeta logMeta) + uint logIndex = 0; + public virtual async void Write(String[] logs, int offset, int size) { - if (this._isWriter) + var buffers = System.Buffers.ArrayPool.Shared.Rent(Mtu); + var h = logIndex++; + String root = logs[0]; + + for (var i = 1; i < size; i += 2) { - UdpWriter writer; - if (_logMetas.TryDequeue(out writer)) + + var log = logs[i + 1]; + if (String.IsNullOrEmpty(log) == false) { + int index = 0; + index += $"<13>{DateTime.Now:u} {root} {logs[i]}[{h}]:".WriteBytes(buffers, index); + for (var c = 0; c < log.Length; c++) + { + index += Encoding.UTF8.GetBytes(log, c, 1, buffers, index); + if (index + 5 > Mtu) + { + break; + } + } + await this.client.SendAsync(buffers.AsMemory(0, index)); + }else{ + } - else - { - writer = new UdpWriter(this.client); - - } - UMC.Data.JSON.Serialize(logMeta, writer); - writer.Flush(); - _logMetas.Enqueue(writer); } + System.Buffers.ArrayPool.Shared.Return(buffers); } public static void Instance(LogSetting logSetting, Provider provider) { diff --git a/Proxy/SiteServerActivity.cs b/Proxy/SiteServerActivity.cs index b36de5b..fb4d0ea 100644 --- a/Proxy/SiteServerActivity.cs +++ b/Proxy/SiteServerActivity.cs @@ -36,7 +36,7 @@ namespace UMC.ITME.Activities ui.AddCell("主协议", provider["scheme"] ?? "http", new UIClick(request.Model, request.Command, "Domain")) .AddCell("主域名", provider["domain"] ?? "未设置", new UIClick(request.Model, request.Command, "Domain")); - ui.NewSection().AddCell("日志组件", new UIClick(request, "Log")); + ui.NewSection().AddCell("日志服务", new UIClick(request, "Log")); @@ -91,14 +91,6 @@ namespace UMC.ITME.Activities var cell = UI.UI(p.Attributes["port"] ?? "80", p.Attributes["server"]);//, new UIClick(p.Name).Send(request.Model, request.Command)); tcpUI.Delete(cell, new UIEventText().Click(new UIClick(request, akey, p.Name, "Type", "Del"))); } - - // } - // else - // { - // UIDesc desc = new UIDesc("未配置tcp报文转发服务"); - // desc.Desc("{icon}\n{desc}").Put("icon", "\uf24a"); - // desc.Style.Align(1).Color(0xaaa).Padding(20, 20).BgColor(0xfff).Size(12).Name("icon", new UIStyle().Font("wdk").Size(60)); - // tcpUI.Add(desc); } var udp = hosts.Providers.Where(r => r.Type == "udp"); @@ -112,14 +104,6 @@ namespace UMC.ITME.Activities var cell = UI.UI(p.Attributes["port"], p.Attributes["server"]);//, new UIClick(p.Name).Send(request.Model, request.Command)); udpUI.Delete(cell, new UIEventText().Click(new UIClick(request, akey, p.Name, "Type", "Del"))); } - - // } - // else - // { - // UIDesc desc = new UIDesc("未配置udp报文转发服务"); - // desc.Desc("{icon}\n{desc}").Put("icon", "\uf24a"); - // desc.Style.Align(1).Color(0xaaa).Padding(20, 20).BgColor(0xfff).Size(12).Name("icon", new UIStyle().Font("wdk").Size(60)); - // udpUI.Add(desc); } @@ -185,21 +169,28 @@ namespace UMC.ITME.Activities { var provider = UMC.Data.Reflection.Configuration("assembly")?["Log"]; - var fm = new UIFormDialog() { Title = "网关服务器日志" }; - fm.AddText("日志服务器", "host", provider?["hsot"]).NotRequired(); - fm.AddNumber("服务器端口", "port", provider?["port"] ?? "5188").NotRequired(); + var fm = new UIFormDialog() { Title = "日志服务器" }; + fm.AddText("服务器", "host", provider?["host"]).NotRequired(); + fm.AddNumber("端口", "port", provider?["port"] ?? "514").NotRequired(); + fm.AddFooter("采用Syslog格式吐出日志"); fm.Submit("确认", $"{request.Model}.{request.Command}"); return fm; }); + var cfg = UMC.Data.Reflection.Configuration("assembly"); var p = Provider.Create("Log", "LogSetting"); - if (String.IsNullOrEmpty(setting["host"]) == false) + if (String.IsNullOrEmpty(setting["host"]) || String.IsNullOrEmpty(setting["port"])) + { + cfg.Remove("Log"); + } + else + { p.Attributes["host"] = setting["host"]; - if (String.IsNullOrEmpty(setting["port"]) == false) p.Attributes["port"] = setting["port"]; - var cfg = UMC.Data.Reflection.Configuration("assembly"); - cfg.Add(p); + cfg.Add(p); + } UMC.Data.Reflection.Configuration("assembly", cfg); LogSetting.Instance().LoadConf(); + this.Context.Send($"{request.Model}.{request.Command}", true); } break; case "Unix": diff --git a/Proxy/WebFactory.cs b/Proxy/WebFactory.cs index 7cd8f6e..8a3d848 100644 --- a/Proxy/WebFactory.cs +++ b/Proxy/WebFactory.cs @@ -15,6 +15,18 @@ namespace UMC.ITME [Apiumc(Weight = 0, Desc = "云模块服务组件")] public class WebFactory : IWebFactory { + class XHRException : Exception + { + String _t; + public XHRException(String xhr) + { + _t = xhr; + } + public override string ToString() + { + return _t; + } + } internal static Dictionary>> Auths = new Dictionary>>(); class XHRActivity : WebActivity @@ -198,7 +210,7 @@ namespace UMC.ITME sb.Append(Uri.EscapeDataString(String.Join('/', stv))); } } - + var query = request.Url.Query ?? ""; if (query.StartsWith("?_v=")) { @@ -215,24 +227,24 @@ namespace UMC.ITME webReq.ContentType = "application/x-www-form-urlencoded"; webReq.Post(sb.ToString(), res => { + int StatusCode = (int)res.StatusCode; + HttpProxy.LogWrite(httpProxy.Context, httpProxy.Site, 200, webReq.RawUrl, httpProxy.SiteCookie.Account, null, String.Empty); if (StatusCode > 300 && StatusCode < 400) { httpProxy.ProcessEnd(); var url = res.Headers.Get("Location"); - - response.Redirect(new Uri(content.Url, url)); - + response.Headers.Put("Data", new Uri(content.Url, url)); + response.ClientEvent |= (WebEvent)131072; this.Context.OutputFinish(); + } - else + else if (StatusCode == 200) { res.ReadAsString(xhr => { - httpProxy.ProcessEnd(); - String eventPfx = "{\"ClientEvent\":"; - if (xhr.StartsWith(eventPfx)) + if (xhr.StartsWith("{\"ClientEvent\":")) { var xData = JSON.Deserialize(xhr) as Hashtable; @@ -255,6 +267,7 @@ namespace UMC.ITME var cmd = redirect["cmd"] as string; if (String.IsNullOrEmpty(model) == false && String.IsNullOrEmpty(cmd) == false) { + this.Context.Items[$"XHR.{model}.{cmd}"] = site.Root; var send = redirect["send"]; if (send is IDictionary) { @@ -279,8 +292,8 @@ namespace UMC.ITME response.Headers.Put("Data", Data.JSON.Expression(xhr)); response.ClientEvent |= (WebEvent)131072; } - this.Context.OutputFinish(); + }, error => { if (error is WebAbortException) @@ -293,6 +306,19 @@ namespace UMC.ITME } }); } + else + { + // httpProxy.ProcessEnd(); + if (res.Error != null) + { + this.Prompt(site.Site.Caption, $"异常:{res.Error.Message}.", false); + this.Context.OutputFinish(); + } + else + { + res.Transfer(this.Context.Client.Context); + } + } }); response.Redirect(Empty); @@ -309,8 +335,11 @@ namespace UMC.ITME var p = cgf[$"{m}.{cmd}"] ?? cgf[$"{m}.*"]; if (p != null) { + var root = p.Attributes["root"]; - if (String.IsNullOrEmpty(root) == false) + + var lold = this.Context.Items[$"XHR.{m}.{cmd}"] as string; + if (String.IsNullOrEmpty(root) == false && String.Equals(lold, root) == false) { var site = DataFactory.Instance().SiteConfig(p.Attributes["root"]); if (site != null) diff --git a/Proxy/WebServlet.cs b/Proxy/WebServlet.cs index b3bbb0f..08dc5e4 100644 --- a/Proxy/WebServlet.cs +++ b/Proxy/WebServlet.cs @@ -2051,14 +2051,14 @@ namespace UMC.ITME context.Tag = WebTransfer(siteConfig, context, RawUrl); return; } - var startTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); + // var startTime = UMC.Data.Reflection.TimeSpanMilli(DateTime.Now); NameValueCollection resHeaders = null; String _attachmentFile = null; context.UseSynchronousIO(() => { - var duration = (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - startTime); + // var duration = (int)(UMC.Data.Reflection.TimeSpanMilli(DateTime.Now) - startTime); - HttpProxy.LogWrite(context, siteConfig, context.StatusCode, String.Format("{0} {1}", context.HttpMethod, context.Url.PathAndQuery), null, duration, resHeaders, _attachmentFile); + HttpProxy.LogWrite(context, siteConfig, String.Empty, resHeaders, _attachmentFile); }); if (siteConfig.IsFile)