Skip to content

Commit

Permalink
👩‍🦰 add Remote client miniprofiler support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Mar 23, 2021
1 parent 408e9a1 commit 56a76e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 16 additions & 2 deletions framework/Furion/RemoteRequest/Internal/HttpClientPartMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace Furion.RemoteRequest
/// </summary>
public sealed partial class HttpClientPart
{
/// <summary>
/// MiniProfiler 分类名
/// </summary>
private const string MiniProfilerCategory = "httpclient";

/// <summary>
/// 发送 GET 请求返回 T 对象
/// </summary>
Expand Down Expand Up @@ -256,11 +261,11 @@ public async Task<HttpResponseMessage> SendAsync(CancellationToken cancellationT
// 检查请求地址
if (string.IsNullOrEmpty(RequestUrl)) throw new NullReferenceException(RequestUrl);

var finalRequestUrl = RequestUrl;

// 处理模板问题
ReplaceRequestUrlTemplates();

var finalRequestUrl = RequestUrl;

// 拼接查询参数
if (Queries != null && Queries.Count > 0)
{
Expand Down Expand Up @@ -313,12 +318,18 @@ public async Task<HttpResponseMessage> SendAsync(CancellationToken cancellationT
u?.Invoke(httpClient);
});

// 打印发送请求
App.PrintToMiniProfiler(MiniProfilerCategory, "Sending", $"[{Method}] {finalRequestUrl}");

// 发送请求
var response = await httpClient.SendAsync(request, cancellationToken);

// 请求成功
if (response.IsSuccessStatusCode)
{
// 打印成功请求
App.PrintToMiniProfiler(MiniProfilerCategory, "Succeeded", $"[StatusCode: {response.StatusCode}] Succeeded");

// 调用成功拦截器
ResponseInterceptors.ForEach(u =>
{
Expand All @@ -331,6 +342,9 @@ public async Task<HttpResponseMessage> SendAsync(CancellationToken cancellationT
// 读取错误消息
var errors = await response.Content.ReadAsStringAsync(cancellationToken);

// 打印失败请求
App.PrintToMiniProfiler(MiniProfilerCategory, "Failed", $"[StatusCode: {response.StatusCode}] {errors}", true);

// 抛出异常
if (ExceptionInterceptors == null || ExceptionInterceptors.Count == 0) throw new HttpRequestException(errors);
// 调用异常拦截器
Expand Down
3 changes: 0 additions & 3 deletions samples/Furion.Web.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public void ConfigureServices(IServiceCollection services)

// 添加实时通讯
services.AddSignalR();

// 添加远程请求
services.AddRemoteRequest();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down

0 comments on commit 56a76e8

Please sign in to comment.