Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpConnectionBase.cs
Go to the documentation of this file.
2using System.IO;
6using System.Text;
9
10namespace System.Net.Http;
11
12internal abstract class HttpConnectionBase : IDisposable, IHttpTrace
13{
14 private string _lastDateHeaderValue;
15
16 private string _lastServerHeaderValue;
17
19
21 {
22 if (descriptor.KnownHeader != KnownHeaders.Date)
23 {
24 if (descriptor.KnownHeader != KnownHeaders.Server)
25 {
26 return descriptor.GetHeaderValue(value, valueEncoding);
27 }
28 return GetOrAddCachedValue(ref _lastServerHeaderValue, descriptor, value, valueEncoding);
29 }
30 return GetOrAddCachedValue(ref _lastDateHeaderValue, descriptor, value, valueEncoding);
31 static string GetOrAddCachedValue([NotNull] ref string cache, HeaderDescriptor descriptor, ReadOnlySpan<byte> value, Encoding encoding)
32 {
33 string text = cache;
35 {
36 text = (cache = descriptor.GetHeaderValue(value, encoding));
37 }
38 return text;
39 }
40 }
41
42 public abstract void Trace(string message, [CallerMemberName] string memberName = null);
43
45 {
46 if (stream is SslStream sslStream)
47 {
48 Trace($"{this}. SslProtocol:{sslStream.SslProtocol}, NegotiatedApplicationProtocol:{sslStream.NegotiatedApplicationProtocol}, NegotiatedCipherSuite:{sslStream.NegotiatedCipherSuite}, CipherAlgorithm:{sslStream.CipherAlgorithm}, CipherStrength:{sslStream.CipherStrength}, HashAlgorithm:{sslStream.HashAlgorithm}, HashStrength:{sslStream.HashStrength}, KeyExchangeAlgorithm:{sslStream.KeyExchangeAlgorithm}, KeyExchangeStrength:{sslStream.KeyExchangeStrength}, LocalCertificate:{sslStream.LocalCertificate}, RemoteCertificate:{sslStream.RemoteCertificate}", "TraceConnection");
49 }
50 else
51 {
52 Trace($"{this}", "TraceConnection");
53 }
54 }
55
56 public long GetLifetimeTicks(long nowTicks)
57 {
58 return nowTicks - _creationTickCount;
59 }
60
61 public abstract long GetIdleTicks(long nowTicks);
62
63 public virtual bool CheckUsabilityOnScavenge()
64 {
65 return true;
66 }
67
68 internal static bool IsDigit(byte c)
69 {
70 return (uint)(c - 48) <= 9u;
71 }
72
74 {
75 byte b;
76 byte b2;
77 byte b3;
78 if (value.Length != 3 || !IsDigit(b = value[0]) || !IsDigit(b2 = value[1]) || !IsDigit(b3 = value[2]))
79 {
81 }
82 return 100 * (b - 48) + 10 * (b2 - 48) + (b3 - 48);
83 }
84
85 internal static void IgnoreExceptions(ValueTask<int> task)
86 {
87 if (task.IsCompleted)
88 {
89 if (task.IsFaulted)
90 {
91 _ = task.AsTask().Exception;
92 }
93 }
94 else
95 {
96 task.AsTask().ContinueWith((Task<int> t) => t.Exception, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
97 }
98 }
99
100 internal void LogExceptions(Task task)
101 {
102 if (task.IsCompleted)
103 {
104 if (task.IsFaulted)
105 {
106 LogFaulted(this, task);
107 }
108 }
109 else
110 {
111 task.ContinueWith(delegate(Task t, object state)
112 {
113 LogFaulted((HttpConnectionBase)state, t);
114 }, this, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
115 }
116 static void LogFaulted(HttpConnectionBase connection, Task task)
117 {
118 Exception innerException = task.Exception.InnerException;
119 if (System.Net.NetEventSource.Log.IsEnabled())
120 {
121 connection.Trace($"Exception from asynchronous processing: {innerException}", "LogExceptions");
122 }
123 }
124 }
125
126 public abstract void Dispose();
127}
static bool EqualsOrdinalAscii(string left, ReadOnlySpan< byte > right)
static long TickCount64
static readonly KnownHeader Date
static readonly KnownHeader Server
string GetResponseHeaderValueWithCaching(HeaderDescriptor descriptor, ReadOnlySpan< byte > value, Encoding valueEncoding)
void Trace(string message, [CallerMemberName] string memberName=null)
long GetIdleTicks(long nowTicks)
static int ParseStatusCode(ReadOnlySpan< byte > value)
static void IgnoreExceptions(ValueTask< int > task)
static readonly System.Net.NetEventSource Log
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_http_invalid_response_status_code
Definition SR.cs:108
Definition SR.cs:7
static Encoding ASCII
Definition Encoding.cs:511
AggregateException? Exception
Definition Task.cs:1014
string GetHeaderValue(ReadOnlySpan< byte > headerValue, Encoding valueEncoding)