更新Linux截图

HttpClient 统一到 HttpClientFactory
This commit is contained in:
Aigio Liu
2021-02-23 12:05:22 +08:00
parent a0226c8d3a
commit a85f977ccf
24 changed files with 349 additions and 107 deletions
@@ -0,0 +1,14 @@
using System.IO;
namespace System.Net.Http
{
/// <inheritdoc cref="IHttpPlatformHelper"/>
public class HttpPlatformHelper : IHttpPlatformHelper
{
const string DefaultUserAgent = "Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263";
public virtual string UserAgent => DefaultUserAgent;
public (string filePath, string mime)? TryHandleUploadFile(Stream fileStream) => null;
}
}
@@ -0,0 +1,40 @@
using Microsoft.Extensions.Logging;
namespace System.Net.Http
{
public abstract class HttpService
{
protected readonly ILogger logger;
readonly IHttpClientFactory _clientFactory;
public HttpService(
ILogger logger,
IHttpClientFactory clientFactory)
{
this.logger = logger;
_clientFactory = clientFactory;
}
/// <summary>
/// 用于 <see cref="IHttpClientFactory.CreateClient(string)"/> 中传递的 name
/// <para>如果为 <see langword="null"/> 则调用 <see cref="HttpClientFactoryExtensions.CreateClient(IHttpClientFactory)"/></para>
/// <para>默认值为 <see langword="null"/></para>
/// </summary>
protected virtual string? ClientName { get; }
protected virtual HttpClient CreateClient()
{
#if DEBUG
logger.LogDebug("CreateClient, name: {0}", ClientName);
#endif
if (ClientName == null)
{
return _clientFactory.CreateClient();
}
else
{
return _clientFactory.CreateClient(ClientName);
}
}
}
}
@@ -0,0 +1,26 @@
using System.IO;
namespace System.Net.Http
{
/// <summary>
/// 由平台实现的HTTP工具助手
/// </summary>
public interface IHttpPlatformHelper
{
/// <summary>
/// 用户代理
/// <para>https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent</para>
/// <para>通常可以从平台的WebView控件中调用js获取</para>
/// </summary>
string UserAgent { get; }
/// <summary>
/// 尝试将需要上传的文件流[处理]后保存到临时路径中并返回信息
/// <para>[处理]由客户端平台原生实现</para>
/// <para>例如:文件压缩、格式转换(heic)</para>
/// </summary>
/// <param name="fileStream"></param>
/// <returns></returns>
(string filePath, string mime)? TryHandleUploadFile(Stream fileStream);
}
}