Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WebRequest.cs
Go to the documentation of this file.
3using System.IO;
11
12namespace System.Net;
13
15{
16 internal sealed class WebRequestPrefixElement
17 {
18 public readonly string Prefix;
19
20 public readonly IWebRequestCreate Creator;
21
27 }
28
29 internal sealed class HttpRequestCreator : IWebRequestCreate
30 {
32 {
33 return new HttpWebRequest(Uri);
34 }
35 }
36
38
39 private static object s_internalSyncObject = new object();
40
42
43 private static bool s_DefaultWebProxyInitialized;
44
68
69 public static RequestCachePolicy? DefaultCachePolicy { get; set; } = new RequestCachePolicy(RequestCacheLevel.BypassCache);
70
71
72 public virtual RequestCachePolicy? CachePolicy { get; set; }
73
74 public AuthenticationLevel AuthenticationLevel { get; set; } = AuthenticationLevel.MutualAuthRequested;
75
76
77 public TokenImpersonationLevel ImpersonationLevel { get; set; } = TokenImpersonationLevel.Delegation;
78
79
91
103
104 public virtual Uri RequestUri
105 {
106 get
107 {
109 }
110 }
111
123
135
147
160
172
184
186 {
187 get
188 {
190 }
191 set
192 {
194 {
197 }
198 }
199 }
200
212
224
225 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
226 protected WebRequest()
227 {
228 }
229
230 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
235
240
245
247 {
249 bool flag = false;
250 string text = (useUriBase ? (requestUri.Scheme + ":") : requestUri.AbsoluteUri);
251 int length = text.Length;
253 for (int i = 0; i < prefixList.Count; i++)
254 {
256 if (length >= webRequestPrefixElement.Prefix.Length && string.Compare(webRequestPrefixElement.Prefix, 0, text, 0, webRequestPrefixElement.Prefix.Length, StringComparison.OrdinalIgnoreCase) == 0)
257 {
258 flag = true;
259 break;
260 }
261 }
262 if (flag)
263 {
264 return webRequestPrefixElement.Creator.Create(requestUri);
265 }
267 }
268
269 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
270 public static WebRequest Create(string requestUriString)
271 {
272 if (requestUriString == null)
273 {
274 throw new ArgumentNullException("requestUriString");
275 }
276 return Create(new Uri(requestUriString), useUriBase: false);
277 }
278
279 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
281 {
282 if (requestUri == null)
283 {
284 throw new ArgumentNullException("requestUri");
285 }
286 return Create(requestUri, useUriBase: false);
287 }
288
289 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
291 {
292 if (requestUri == null)
293 {
294 throw new ArgumentNullException("requestUri");
295 }
296 return Create(requestUri, useUriBase: true);
297 }
298
299 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
301 {
302 if (requestUriString == null)
303 {
304 throw new ArgumentNullException("requestUriString");
305 }
306 return CreateHttp(new Uri(requestUriString));
307 }
308
309 [Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId = "SYSLIB0014", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
311 {
312 if (requestUri == null)
313 {
314 throw new ArgumentNullException("requestUri");
315 }
316 if (requestUri.Scheme != "http" && requestUri.Scheme != "https")
317 {
319 }
321 }
322
323 public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
324 {
325 bool flag = false;
326 if (prefix == null)
327 {
328 throw new ArgumentNullException("prefix");
329 }
330 if (creator == null)
331 {
332 throw new ArgumentNullException("creator");
333 }
335 {
337 if (Uri.TryCreate(prefix, UriKind.Absolute, out Uri result))
338 {
339 string text = result.AbsoluteUri;
340 if (!prefix.EndsWith('/') && result.GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment, UriFormat.UriEscaped).Equals("/"))
341 {
342 text = text.Substring(0, text.Length - 1);
343 }
344 prefix = text;
345 }
346 int i;
347 for (i = 0; i < list.Count; i++)
348 {
350 if (prefix.Length > webRequestPrefixElement.Prefix.Length)
351 {
352 break;
353 }
354 if (prefix.Length == webRequestPrefixElement.Prefix.Length && string.Equals(webRequestPrefixElement.Prefix, prefix, StringComparison.OrdinalIgnoreCase))
355 {
356 flag = true;
357 break;
358 }
359 }
360 if (!flag)
361 {
364 }
365 }
366 return !flag;
367 }
368
373
378
379 public virtual IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
380 {
382 }
383
388
389 public virtual IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state)
390 {
392 }
393
398
400 {
401 return Task.Run(() => Task<Stream>.Factory.FromAsync((AsyncCallback callback, object state) => ((WebRequest)state).BeginGetRequestStream(callback, state), (IAsyncResult iar) => ((WebRequest)iar.AsyncState).EndGetRequestStream(iar), this));
402 }
403
405 {
406 return Task.Run(() => Task<WebResponse>.Factory.FromAsync((AsyncCallback callback, object state) => ((WebRequest)state).BeginGetResponse(callback, state), (IAsyncResult iar) => ((WebRequest)iar.AsyncState).EndGetResponse(iar), this));
407 }
408
413
415 {
417 }
418}
static IWebProxy DefaultProxy
Definition HttpClient.cs:40
WebRequestPrefixElement(string prefix, IWebRequestCreate creator)
Definition WebRequest.cs:22
virtual Task< WebResponse > GetResponseAsync()
static IWebProxy GetSystemWebProxy()
virtual bool UseDefaultCredentials
virtual ? ICredentials Credentials
virtual string Method
Definition WebRequest.cs:93
static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
static ? IWebProxy DefaultWebProxy
virtual IAsyncResult BeginGetResponse(AsyncCallback? callback, object? state)
static WebRequest Create(Uri requestUri, bool useUriBase)
virtual void Abort()
virtual ? string ContentType
virtual void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
virtual WebResponse EndGetResponse(IAsyncResult asyncResult)
static HttpWebRequest CreateHttp(Uri requestUri)
virtual ? IWebProxy Proxy
virtual Uri RequestUri
WebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext)
static ? RequestCachePolicy DefaultCachePolicy
Definition WebRequest.cs:69
virtual ? string ConnectionGroupName
Definition WebRequest.cs:81
static bool s_DefaultWebProxyInitialized
Definition WebRequest.cs:43
static List< WebRequestPrefixElement > PrefixList
Definition WebRequest.cs:46
virtual ? RequestCachePolicy CachePolicy
Definition WebRequest.cs:72
virtual Task< Stream > GetRequestStreamAsync()
virtual WebResponse GetResponse()
virtual Stream GetRequestStream()
static HttpWebRequest CreateHttp(string requestUriString)
static List< WebRequestPrefixElement > s_prefixList
Definition WebRequest.cs:37
static IWebProxy s_DefaultWebProxy
Definition WebRequest.cs:41
static WebRequest Create(string requestUriString)
virtual long ContentLength
static object s_internalSyncObject
Definition WebRequest.cs:39
static WebRequest CreateDefault(Uri requestUri)
virtual Stream EndGetRequestStream(IAsyncResult asyncResult)
virtual bool PreAuthenticate
static WebRequest Create(Uri requestUri)
virtual IAsyncResult BeginGetRequestStream(AsyncCallback? callback, object? state)
static Exception ByDesignWithMessage(string message)
static string net_unknown_prefix
Definition SR.cs:14
static string net_MethodNotImplementedException
Definition SR.cs:22
static string net_PropertyNotImplementedException
Definition SR.cs:80
Definition SR.cs:7
static Task Run(Action action)
Definition Task.cs:3395
static void Write(ref bool location, bool value)
Definition Volatile.cs:74
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
void GetObjectData(SerializationInfo info, StreamingContext context)
UriKind
Definition UriKind.cs:4
UriFormat
Definition UriFormat.cs:4