Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpMessageInvoker.cs
Go to the documentation of this file.
4
5namespace System.Net.Http;
6
8{
9 private volatile bool _disposed;
10
11 private readonly bool _disposeHandler;
12
13 private readonly HttpMessageHandler _handler;
14
16 : this(handler, disposeHandler: true)
17 {
18 }
19
20 public HttpMessageInvoker(HttpMessageHandler handler, bool disposeHandler)
21 {
22 if (handler == null)
23 {
24 throw new ArgumentNullException("handler");
25 }
26 if (System.Net.NetEventSource.Log.IsEnabled())
27 {
28 System.Net.NetEventSource.Associate(this, handler, ".ctor");
29 }
30 _handler = handler;
31 _disposeHandler = disposeHandler;
32 }
33
34 [UnsupportedOSPlatform("browser")]
36 {
37 if (request == null)
38 {
39 throw new ArgumentNullException("request");
40 }
42 if (ShouldSendWithTelemetry(request))
43 {
44 HttpTelemetry.Log.RequestStart(request);
45 try
46 {
47 return _handler.Send(request, cancellationToken);
48 }
49 catch when (LogRequestFailed(telemetryStarted: true))
50 {
51 throw;
52 }
53 finally
54 {
55 HttpTelemetry.Log.RequestStop();
56 }
57 }
58 return _handler.Send(request, cancellationToken);
59 }
60
62 {
63 if (request == null)
64 {
65 throw new ArgumentNullException("request");
66 }
68 if (ShouldSendWithTelemetry(request))
69 {
70 return SendAsyncWithTelemetry(_handler, request, cancellationToken);
71 }
72 return _handler.SendAsync(request, cancellationToken);
74 {
75 HttpTelemetry.Log.RequestStart(request);
76 try
77 {
78 return await handler.SendAsync(request, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
79 }
80 catch when (LogRequestFailed(telemetryStarted: true))
81 {
82 throw;
83 }
84 finally
85 {
86 HttpTelemetry.Log.RequestStop();
87 }
88 }
89 }
90
91 private static bool ShouldSendWithTelemetry(HttpRequestMessage request)
92 {
93 if (HttpTelemetry.Log.IsEnabled() && !request.WasSentByHttpClient())
94 {
95 Uri requestUri = request.RequestUri;
96 if ((object)requestUri != null)
97 {
98 return requestUri.IsAbsoluteUri;
99 }
100 }
101 return false;
102 }
103
104 internal static bool LogRequestFailed(bool telemetryStarted)
105 {
106 if (HttpTelemetry.Log.IsEnabled() && telemetryStarted)
107 {
108 HttpTelemetry.Log.RequestFailed();
109 }
110 return false;
111 }
112
113 public void Dispose()
114 {
115 Dispose(disposing: true);
116 GC.SuppressFinalize(this);
117 }
118
119 protected virtual void Dispose(bool disposing)
120 {
121 if (disposing && !_disposed)
122 {
123 _disposed = true;
124 if (_disposeHandler)
125 {
127 }
128 }
129 }
130
131 private void CheckDisposed()
132 {
133 if (_disposed)
134 {
135 throw new ObjectDisposedException(GetType().ToString());
136 }
137 }
138}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
virtual HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
virtual void Dispose(bool disposing)
virtual Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
static bool ShouldSendWithTelemetry(HttpRequestMessage request)
HttpMessageInvoker(HttpMessageHandler handler)
readonly HttpMessageHandler _handler
virtual void Dispose(bool disposing)
HttpMessageInvoker(HttpMessageHandler handler, bool disposeHandler)
virtual HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
static bool LogRequestFailed(bool telemetryStarted)
static readonly HttpTelemetry Log
static readonly System.Net.NetEventSource Log
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
bool IsAbsoluteUri
Definition Uri.cs:572