Blame view

netcore/src/Infrastructure/NCC/RemoteRequest/Internal/HttpRequestPart.cs 3.69 KB
de2bd2f9   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  using NCC.JsonSerialization;
  using System;
  using System.Collections.Generic;
  using System.Net.Http;
  using System.Text;
  
  namespace NCC.RemoteRequest
  {
      /// <summary>
      /// Http 请求对象组装部件
      /// </summary>
      public sealed partial class HttpRequestPart
      {
          /// <summary>
          /// 静态缺省请求部件
          /// </summary>
          public static HttpRequestPart Default => new();
  
          /// <summary>
          /// 请求地址
          /// </summary>
          public string RequestUrl { get; private set; }
  
          /// <summary>
          /// Url 地址模板
          /// </summary>
          public IDictionary<string, object> Templates { get; private set; }
  
          /// <summary>
          /// 请求方式
          /// </summary>
          public HttpMethod Method { get; private set; }
  
          /// <summary>
          /// 请求报文头
          /// </summary>
          public IDictionary<string, object> Headers { get; private set; }
  
          /// <summary>
          /// 查询参数
          /// </summary>
          public IDictionary<string, object> Queries { get; private set; }
  
          /// <summary>
          /// 客户端名称
          /// </summary>
          public string ClientName { get; private set; }
  
          /// <summary>
          /// 请求报文 Body 参数
          /// </summary>
          public object Body { get; private set; }
  
          /// <summary>
          /// 请求报文 Body 内容类型
          /// </summary>
          public string ContentType { get; private set; } = "application/json";
  
          /// <summary>
          /// 内容编码
          /// </summary>
          public Encoding ContentEncoding { get; private set; } = Encoding.UTF8;
  
          /// <summary>
          /// 设置 Body Bytes 类型
          /// </summary>
          public List<(string Name, byte[] Bytes, string FileName)> BodyBytes { get; private set; } = new List<(string Name, byte[] Bytes, string FileName)>();
  
          /// <summary>
          /// 超时时间(秒)
          /// </summary>
          public long Timeout { get; private set; }
  
          /// <summary>
          /// JSON 序列化提供器
          /// </summary>
          public Type JsonSerializerProvider { get; private set; } = typeof(SystemTextJsonSerializerProvider);
  
          /// <summary>
          /// JSON 序列化配置选项
          /// </summary>
          public object JsonSerializerOptions { get; private set; }
  
          /// <summary>
          /// 是否启用模型验证
          /// </summary>
          public (bool Enabled, bool IncludeNull) ValidationState { get; private set; } = (false, false);
  
          /// <summary>
          /// 构建请求对象拦截器
          /// </summary>
          public List<Action<HttpRequestMessage>> RequestInterceptors { get; private set; } = new List<Action<HttpRequestMessage>>();
  
          /// <summary>
          /// 创建客户端对象拦截器
          /// </summary>
          public List<Action<HttpClient>> HttpClientInterceptors { get; private set; } = new List<Action<HttpClient>>();
  
          /// <summary>
          /// 请求成功拦截器
          /// </summary>
          public List<Action<HttpResponseMessage>> ResponseInterceptors { get; private set; } = new List<Action<HttpResponseMessage>>();
  
          /// <summary>
          /// 请求异常拦截器
          /// </summary>
          public List<Action<HttpResponseMessage, string>> ExceptionInterceptors { get; private set; } = new List<Action<HttpResponseMessage, string>>();
  
          /// <summary>
          /// 设置请求作用域
          /// </summary>
          public IServiceProvider RequestScoped { get; private set; }
  
          /// <summary>
          /// 设置重试策略
          /// </summary>
          public (int NumRetries, int RetryTimeout)? RetryPolicy { get; private set; }
      }
  }