forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityWebRequest.bindings.cs
More file actions
601 lines (511 loc) · 19.4 KB
/
Copy pathUnityWebRequest.bindings.cs
File metadata and controls
601 lines (511 loc) · 19.4 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using UnityEngineInternal;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
namespace UnityEngine.Networking
{
[StructLayout(LayoutKind.Sequential)]
[UsedByNativeCode]
[NativeHeader("Modules/UnityWebRequest/Public/UnityWebRequestAsyncOperation.h")]
[NativeHeader("UnityWebRequestScriptingClasses.h")]
public class UnityWebRequestAsyncOperation : AsyncOperation
{
public UnityWebRequest webRequest { get; internal set; }
}
[StructLayout(LayoutKind.Sequential)]
[NativeHeader("Modules/UnityWebRequest/Public/UnityWebRequest.h")]
public partial class UnityWebRequest : IDisposable
{
[System.NonSerialized]
internal IntPtr m_Ptr;
[System.NonSerialized]
internal DownloadHandler m_DownloadHandler;
[System.NonSerialized]
internal UploadHandler m_UploadHandler;
[System.NonSerialized]
internal CertificateHandler m_CertificateHandler;
[System.NonSerialized]
internal Uri m_Uri;
internal enum UnityWebRequestMethod
{
Get = 0,
Post = 1,
Put = 2,
Head = 3,
Custom = 4
}
internal enum UnityWebRequestError
{
OK = 0, // No Error
Unknown,
SDKError, // SDK error, such as initialization failed
UnsupportedProtocol,
MalformattedUrl,
CannotResolveProxy,
CannotResolveHost,
CannotConnectToHost,
AccessDenied,
GenericHttpError,
WriteError,
ReadError,
OutOfMemory,
Timeout,
HTTPPostError,
SSLCannotConnect,
Aborted,
TooManyRedirects,
ReceivedNoData,
SSLNotSupported,
FailedToSendData,
FailedToReceiveData,
SSLCertificateError,
SSLCipherNotAvailable,
SSLCACertError,
UnrecognizedContentEncoding,
LoginFailed,
SSLShutdownFailed,
NoInternetConnection
}
public const string kHttpVerbGET = "GET";
public const string kHttpVerbHEAD = "HEAD";
public const string kHttpVerbPOST = "POST";
public const string kHttpVerbPUT = "PUT";
public const string kHttpVerbCREATE = "CREATE";
public const string kHttpVerbDELETE = "DELETE";
[NativeMethod(IsThreadSafe = true)]
[NativeConditional("ENABLE_UNITYWEBREQUEST")]
private extern static string GetWebErrorString(UnityWebRequestError err);
[VisibleToOtherModules]
internal extern static string GetHTTPStatusString(long responseCode);
public bool disposeCertificateHandlerOnDispose { get; set; }
public bool disposeDownloadHandlerOnDispose { get; set; }
public bool disposeUploadHandlerOnDispose { get; set; }
public static void ClearCookieCache()
{
ClearCookieCache(null, null);
}
public static void ClearCookieCache(Uri uri)
{
if (uri == null)
ClearCookieCache(null, null);
else
{
string domain = uri.Host;
string path = uri.AbsolutePath;
if (path == "/")
path = null;
ClearCookieCache(domain, path);
}
}
private static extern void ClearCookieCache(string domain, string path);
internal extern static IntPtr Create();
[NativeMethod(IsThreadSafe = true)]
private extern void Release();
internal void InternalDestroy()
{
if (m_Ptr != IntPtr.Zero)
{
Abort();
Release();
m_Ptr = IntPtr.Zero;
}
}
private void InternalSetDefaults()
{
this.disposeDownloadHandlerOnDispose = true;
this.disposeUploadHandlerOnDispose = true;
this.disposeCertificateHandlerOnDispose = true;
}
public UnityWebRequest()
{
m_Ptr = Create();
InternalSetDefaults();
}
public UnityWebRequest(string url)
{
m_Ptr = Create();
InternalSetDefaults();
this.url = url;
}
public UnityWebRequest(Uri uri)
{
m_Ptr = Create();
InternalSetDefaults();
this.uri = uri;
}
public UnityWebRequest(string url, string method)
{
m_Ptr = Create();
InternalSetDefaults();
this.url = url;
this.method = method;
}
public UnityWebRequest(Uri uri, string method)
{
m_Ptr = Create();
InternalSetDefaults();
this.uri = uri;
this.method = method;
}
public UnityWebRequest(string url, string method, DownloadHandler downloadHandler, UploadHandler uploadHandler)
{
m_Ptr = Create();
InternalSetDefaults();
this.url = url;
this.method = method;
this.downloadHandler = downloadHandler;
this.uploadHandler = uploadHandler;
}
public UnityWebRequest(Uri uri, string method, DownloadHandler downloadHandler, UploadHandler uploadHandler)
{
m_Ptr = Create();
InternalSetDefaults();
this.uri = uri;
this.method = method;
this.downloadHandler = downloadHandler;
this.uploadHandler = uploadHandler;
}
~UnityWebRequest()
{
DisposeHandlers();
InternalDestroy();
}
public void Dispose()
{
DisposeHandlers();
InternalDestroy();
GC.SuppressFinalize(this);
}
private void DisposeHandlers()
{
if (disposeDownloadHandlerOnDispose)
{
DownloadHandler dh = this.downloadHandler;
if (dh != null)
{
dh.Dispose();
}
}
if (disposeUploadHandlerOnDispose)
{
UploadHandler uh = this.uploadHandler;
if (uh != null)
{
uh.Dispose();
}
}
if (disposeCertificateHandlerOnDispose)
{
CertificateHandler ch = this.certificateHandler;
if (ch != null)
{
ch.Dispose();
}
}
}
[NativeThrows]
internal extern UnityWebRequestAsyncOperation BeginWebRequest();
[Obsolete("Use SendWebRequest. It returns a UnityWebRequestAsyncOperation which contains a reference to the WebRequest object.", false)]
public AsyncOperation Send() {return SendWebRequest(); }
public UnityWebRequestAsyncOperation SendWebRequest()
{
UnityWebRequestAsyncOperation webOp = BeginWebRequest();
if (webOp != null)
webOp.webRequest = this;
return webOp;
}
[NativeMethod(IsThreadSafe = true)]
public extern void Abort();
private extern UnityWebRequestError SetMethod(UnityWebRequestMethod methodType);
internal void InternalSetMethod(UnityWebRequestMethod methodType)
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its request method can no longer be altered");
UnityWebRequestError ret = SetMethod(methodType);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
private extern UnityWebRequestError SetCustomMethod(string customMethodName);
internal void InternalSetCustomMethod(string customMethodName)
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its request method can no longer be altered");
UnityWebRequestError ret = SetCustomMethod(customMethodName);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
internal extern UnityWebRequestMethod GetMethod();
internal extern string GetCustomMethod();
public string method
{
get
{
UnityWebRequestMethod m = GetMethod();
switch (m)
{
case UnityWebRequestMethod.Get:
return kHttpVerbGET;
case UnityWebRequestMethod.Post:
return kHttpVerbPOST;
case UnityWebRequestMethod.Put:
return kHttpVerbPUT;
case UnityWebRequestMethod.Head:
return kHttpVerbHEAD;
default:
return GetCustomMethod();
}
}
set
{
if (String.IsNullOrEmpty(value))
{
throw new ArgumentException("Cannot set a UnityWebRequest's method to an empty or null string");
}
switch (value.ToUpper())
{
case kHttpVerbGET:
InternalSetMethod(UnityWebRequestMethod.Get);
break;
case kHttpVerbPOST:
InternalSetMethod(UnityWebRequestMethod.Post);
break;
case kHttpVerbPUT:
InternalSetMethod(UnityWebRequestMethod.Put);
break;
case kHttpVerbHEAD:
InternalSetMethod(UnityWebRequestMethod.Head);
break;
default:
InternalSetCustomMethod(value.ToUpper());
break;
}
}
}
private extern UnityWebRequestError GetError();
public string error
{
get
{
if (!(isNetworkError || isHttpError))
return null;
if (isHttpError)
{
string status = UnityWebRequest.GetHTTPStatusString(responseCode);
return string.Format("HTTP/1.1 {0} {1}", responseCode, status);
}
else
{
return UnityWebRequest.GetWebErrorString(GetError());
}
}
}
private extern bool use100Continue { get; set; }
public bool useHttpContinue
{
get { return use100Continue; }
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its 100-Continue setting cannot be altered");
use100Continue = value;
}
}
public string url
{
get
{
return GetUrl();
}
set
{
// We need to sanitize the incoming URL so it's a proper absolute URL
// This permits us to allow relative URLs and correct minor user mistakes.
string localUrl = "http://localhost/";
InternalSeturl(WebRequestUtils.MakeInitialUrl(value, localUrl));
}
}
public Uri uri
{
get
{
// always return from native (it will change in case of redirect)
return new Uri(GetUrl());
}
set
{
if (!value.IsAbsoluteUri)
throw new ArgumentException("URI must be absolute");
InternalSeturl(WebRequestUtils.MakeUriString(value, value.OriginalString, false));
m_Uri = value;
}
}
private extern string GetUrl();
private extern UnityWebRequestError Seturl(string url);
private void InternalSeturl(string url)
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its URL cannot be altered");
UnityWebRequestError ret = Seturl(url);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
public extern long responseCode { get; }
private extern float GetUploadProgress();
private extern bool IsExecuting();
public float uploadProgress
{
get
{
if (!(IsExecuting() || isDone))
return -1.0f;
else
return GetUploadProgress();
}
}
public extern bool isModifiable {[NativeMethod("IsModifiable")] get; }
public extern bool isDone {[NativeMethod("IsDone")] get; }
public extern bool isNetworkError {[NativeMethod("IsNetworkError")] get; }
public extern bool isHttpError {[NativeMethod("IsHttpError")] get; }
private extern float GetDownloadProgress();
public float downloadProgress
{
get
{
if (!(IsExecuting() || isDone))
return -1.0f;
else
return GetDownloadProgress();
}
}
public extern ulong uploadedBytes { get; }
public extern ulong downloadedBytes { get; }
private extern int GetRedirectLimit();
[NativeThrows]
private extern void SetRedirectLimitFromScripting(int limit);
public int redirectLimit
{
get { return GetRedirectLimit(); }
set { SetRedirectLimitFromScripting(value); }
}
private extern bool GetChunked();
private extern UnityWebRequestError SetChunked(bool chunked);
public bool chunkedTransfer
{
get { return GetChunked(); }
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its chunked transfer encoding setting cannot be altered");
UnityWebRequestError ret = SetChunked(value);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
}
public extern string GetRequestHeader(string name);
[NativeMethod("SetRequestHeader")]
internal extern UnityWebRequestError InternalSetRequestHeader(string name, string value);
public void SetRequestHeader(string name, string value)
{
if (String.IsNullOrEmpty(name))
throw new ArgumentException("Cannot set a Request Header with a null or empty name");
// Only check for null here, as in general header value can be empty, i.e. Accept-Encoding can have empty value according spec.
if (value == null)
throw new ArgumentException("Cannot set a Request header with a null");
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent and its request headers cannot be altered");
UnityWebRequestError ret = InternalSetRequestHeader(name, value);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
public extern string GetResponseHeader(string name);
internal extern string[] GetResponseHeaderKeys();
public Dictionary<string, string> GetResponseHeaders()
{
string[] headerKeys = GetResponseHeaderKeys();
if (headerKeys == null || headerKeys.Length == 0)
{
return null;
}
Dictionary<string, string> headers = new Dictionary<string, string>(headerKeys.Length, StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < headerKeys.Length; i++)
{
string val = GetResponseHeader(headerKeys[i]);
headers.Add(headerKeys[i], val);
}
return headers;
}
private extern UnityWebRequestError SetUploadHandler(UploadHandler uh);
public UploadHandler uploadHandler
{
get
{
return m_UploadHandler;
}
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent; cannot modify the upload handler");
UnityWebRequestError ret = SetUploadHandler(value);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
m_UploadHandler = value;
}
}
private extern UnityWebRequestError SetDownloadHandler(DownloadHandler dh);
public DownloadHandler downloadHandler
{
get
{
return m_DownloadHandler;
}
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent; cannot modify the download handler");
UnityWebRequestError ret = SetDownloadHandler(value);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
m_DownloadHandler = value;
}
}
private extern UnityWebRequestError SetCertificateHandler(CertificateHandler ch);
public CertificateHandler certificateHandler
{
get
{
return m_CertificateHandler;
}
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent; cannot modify the certificate handler");
UnityWebRequestError ret = SetCertificateHandler(value);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
m_CertificateHandler = value;
}
}
private extern int GetTimeoutMsec();
private extern UnityWebRequestError SetTimeoutMsec(int timeout);
public int timeout
{
get { return GetTimeoutMsec() / 1000; }
set
{
if (!isModifiable)
throw new InvalidOperationException("UnityWebRequest has already been sent; cannot modify the timeout");
value = Math.Max(value, 0);
UnityWebRequestError ret = SetTimeoutMsec(value * 1000);
if (ret != UnityWebRequestError.OK)
throw new InvalidOperationException(UnityWebRequest.GetWebErrorString(ret));
}
}
}
}