diff --git a/Apewer/Apewer.props b/Apewer/Apewer.props index f805432..f831d0e 100644 --- a/Apewer/Apewer.props +++ b/Apewer/Apewer.props @@ -9,7 +9,7 @@ Apewer Apewer Libraries - 6.8.0 + 6.8.1 diff --git a/Apewer/CollectionUtility.cs b/Apewer/CollectionUtility.cs index 4daff30..dcea734 100644 --- a/Apewer/CollectionUtility.cs +++ b/Apewer/CollectionUtility.cs @@ -309,9 +309,9 @@ namespace Apewer } /// 对元素去重,且去除 NULL 值。 - public static T[] Distinct(IEnumerable items) + public static T[] Distinct(this IEnumerable items) { - if (items != null) throw new ArgumentNullException(nameof(items)); + if (items == null) throw new ArgumentNullException(nameof(items)); var count = Count(items); var added = 0; var array = new T[count]; diff --git a/Apewer/Network/HttpClient.cs b/Apewer/Network/HttpClient.cs index e313ac3..b924827 100644 --- a/Apewer/Network/HttpClient.cs +++ b/Apewer/Network/HttpClient.cs @@ -111,6 +111,15 @@ namespace Apewer.Network HttpWebRequest _request = null; HttpWebResponse _response = null; + Nullable _request_time = null; + Nullable _response_time = null; + + /// 发送请求的时间。 + public Nullable RequestTime { get => _request_time; } + + /// 接收响应的时间。 + public Nullable ResponseTime { get => _response_time; } + /// 获取最近发生的异常。 public Exception Exception { get { return _exception; } } @@ -155,11 +164,14 @@ namespace Apewer.Network try { _request = Prepare(url, method); + _request_time = DateTime.Now; _response = _request.GetResponse() as HttpWebResponse; + _response_time = DateTime.Now; Parse(_response); } catch (Exception ex) { + _response_time = DateTime.Now; _exception = ex; if (ex is WebException webEx) Parse((HttpWebResponse)webEx.Response); return ex; @@ -168,7 +180,9 @@ namespace Apewer.Network else { _request = Prepare(url, method); + _request_time = DateTime.Now; _response = _request.GetResponse() as HttpWebResponse; + _response_time = DateTime.Now; Parse(_response); } } diff --git a/Apewer/Network/HttpHeaders.cs b/Apewer/Network/HttpHeaders.cs index 3d1f9b0..3747c9b 100644 --- a/Apewer/Network/HttpHeaders.cs +++ b/Apewer/Network/HttpHeaders.cs @@ -214,6 +214,22 @@ namespace Apewer.Network #region operation + /// 获取所有名称。 + public string[] GetNames() + { + var names = new List(); + var count = _list.Count; + for (var i = 0; i < count; i++) + { + var name = _list[i].Name; + if (string.IsNullOrEmpty(name)) continue; + if (names.Contains(name)) continue; + names.Add(name); + } + names.Sort(); + return names.ToArray(); + } + /// 获取匹配 Name 的 Value。不存在 Name 时返回 NULL 值。 /// public string GetValue(string name) diff --git a/Apewer/StorageUtility.cs b/Apewer/StorageUtility.cs index cf52825..710de58 100644 --- a/Apewer/StorageUtility.cs +++ b/Apewer/StorageUtility.cs @@ -490,16 +490,6 @@ namespace Apewer } } - /// 将数据写入新文件,若文件已存在则覆盖。 - public static bool WriteFile(string path, Json json, bool bom = false) - { - if (string.IsNullOrEmpty(path)) return false; - if (json == null || json.IsNull || json.IsNone) return false; - var text = json.ToString(true); - var bytes = TextUtility.Bytes(text); - return WriteFile(path, bom, bytes); - } - /// 读取文件,获取文件内容。当文件为 UTF-8 文本文件时,可去除 BOM 头。 /// 注:
字节数组最大为 2GB;
此方法不抛出异常,读取失时返回空字节数组。
public static byte[] ReadFile(string path, bool wipeBom = false) diff --git a/Apewer/Web/ApiOptions.cs b/Apewer/Web/ApiOptions.cs index 6208d50..1ff8d97 100644 --- a/Apewer/Web/ApiOptions.cs +++ b/Apewer/Web/ApiOptions.cs @@ -54,8 +54,8 @@ namespace Apewer.Web public ApiPreOutput PreOutput { get; set; } /// 默认的结果渲染器。 - /// 默认值: - public Action TextRenderer { get; set; } = ApiUtility.Error; + /// 默认值:NULL(返回值不为空时视为错误信息) + public Action TextRenderer { get; set; } /// 在响应头中设置 Content-Security-Policy,要求浏览器升级资源链接,使用 HTTPS。 /// 默认值:不要求。在 HTTPS 页面中,不自动升级 HTTP 资源。 diff --git a/Apewer/Web/ApiProcessor.cs b/Apewer/Web/ApiProcessor.cs index 97567a3..4eb2d76 100644 --- a/Apewer/Web/ApiProcessor.cs +++ b/Apewer/Web/ApiProcessor.cs @@ -131,6 +131,7 @@ namespace Apewer.Web var action = _context.Entries.GetAction(path); if (action != null) { + _context.ApiAction = action; Invoke(action); _context.Response.Duration = Duration(_context.Beginning); return; diff --git a/Apewer/_Extensions.cs b/Apewer/_Extensions.cs index 05c683b..b061e20 100644 --- a/Apewer/_Extensions.cs +++ b/Apewer/_Extensions.cs @@ -447,9 +447,6 @@ public static class Extensions /// 获取集合中元素的数量。 public static int Count(this IEnumerable @this) => CollectionUtility.Count(@this); - /// 对元素去重,且去除 NULL 值。 - public static T[] Distinct(this IEnumerable @this) => CollectionUtility.Distinct(@this); - /// 获取可枚举集合的部分元素。 public static T[] Slice(this IEnumerable @this, int start = 0, int count = -1, Func stuffer = null) => CollectionUtility.Slice(@this, start, count, stuffer); diff --git a/ChangeLog.md b/ChangeLog.md index 886d95d..2314286 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,16 @@  ### 最新提交 +### 6.8.1 +- 新特性 + - HttpClient:增加 RequestTime 和 ResponseTime 属性,记录发起请求和接收响应的时间; + - HttpHeaders:增加 GetNames 方法,用于获取所有名称。 +- 问题修正 + - CollectionUtility:修正 Distinct 判断参数为 NULL 时会抛出异常的问题; + - TextUtility:删除 Write(path, json) 方法,以避免传递错误参数导致写文件失败; + - Web:修正 ApiContext.Action 无值的问题; + - Web:修正 ApiOptions.TextRendrer 的默认值,正确的默认值应该是 NULL。 + ### 6.8.0 - 新特性 - ClockUtility:增加 CustomToStamp 和 CustomFromStamp,支持自定义时间戳的转换方法;