forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncHTTPClient.cs
More file actions
292 lines (251 loc) · 6.95 KB
/
Copy pathAsyncHTTPClient.cs
File metadata and controls
292 lines (251 loc) · 6.95 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;
using UnityEngine.Internal;
using UnityEngine.Scripting;
namespace UnityEditor
{
internal sealed class AsyncHTTPClient
{
private delegate void RequestProgressCallback(AsyncHTTPClient.State status, int downloaded, int totalSize);
private delegate void RequestDoneCallback(AsyncHTTPClient.State status, int httpStatus);
internal enum State
{
INIT,
CONNECTING,
CONNECTED,
UPLOADING,
DOWNLOADING,
CONFIRMING,
DONE_OK,
DONE_FAILED,
ABORTED,
TIMEOUT
}
public delegate void DoneCallback(AsyncHTTPClient client);
public delegate void StatusCallback(AsyncHTTPClient.State status, int bytesDone, int bytesTotal);
private IntPtr m_Handle;
public AsyncHTTPClient.StatusCallback statusCallback;
public AsyncHTTPClient.DoneCallback doneCallback;
private string m_ToUrl;
private string m_FromData;
private string m_Method;
public Dictionary<string, string> header;
public string url
{
get
{
return this.m_ToUrl;
}
}
public string text
{
get
{
UTF8Encoding uTF8Encoding = new UTF8Encoding();
byte[] bytes = this.bytes;
string result;
if (bytes == null)
{
result = null;
}
else
{
result = uTF8Encoding.GetString(bytes);
}
return result;
}
}
public byte[] bytes
{
get
{
return AsyncHTTPClient.GetBytesByHandle(this.m_Handle);
}
}
public Texture2D texture
{
get
{
return AsyncHTTPClient.GetTextureByHandle(this.m_Handle);
}
}
public AsyncHTTPClient.State state
{
get;
private set;
}
public int responseCode
{
get;
private set;
}
public string tag
{
get;
set;
}
public string postData
{
set
{
this.m_FromData = value;
if (this.m_Method == "")
{
this.m_Method = "POST";
}
if (!this.header.ContainsKey("Content-Type"))
{
this.header["Content-Type"] = "application/x-www-form-urlencoded";
}
}
}
public Dictionary<string, string> postDictionary
{
set
{
this.postData = string.Join("&", (from kv in value
select this.EscapeLong(kv.Key) + "=" + this.EscapeLong(kv.Value)).ToArray<string>());
}
}
public AsyncHTTPClient(string _toUrl)
{
this.m_ToUrl = _toUrl;
this.m_FromData = null;
this.m_Method = "";
this.state = AsyncHTTPClient.State.INIT;
this.header = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
this.m_Handle = (IntPtr)0;
this.tag = "";
this.statusCallback = null;
}
public AsyncHTTPClient(string _toUrl, string _method)
{
this.m_ToUrl = _toUrl;
this.m_FromData = null;
this.m_Method = _method;
this.state = AsyncHTTPClient.State.INIT;
this.header = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
this.m_Handle = (IntPtr)0;
this.tag = "";
this.statusCallback = null;
}
private static IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate, [DefaultValue("null")] AsyncHTTPClient.RequestProgressCallback progressDelegate)
{
IntPtr result;
AsyncHTTPClient.INTERNAL_CALL_SubmitClientRequest(tag, url, headers, method, data, doneDelegate, progressDelegate, out result);
return result;
}
[ExcludeFromDocs]
private static IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate)
{
AsyncHTTPClient.RequestProgressCallback progressDelegate = null;
IntPtr result;
AsyncHTTPClient.INTERNAL_CALL_SubmitClientRequest(tag, url, headers, method, data, doneDelegate, progressDelegate, out result);
return result;
}
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void INTERNAL_CALL_SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate, AsyncHTTPClient.RequestProgressCallback progressDelegate, out IntPtr value);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern byte[] GetBytesByHandle(IntPtr handle);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Texture2D GetTextureByHandle(IntPtr handle);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void AbortByTag(string tag);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void AbortByHandle(IntPtr handle);
[GeneratedByOldBindingsGenerator]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void CurlRequestCheck();
public void Abort()
{
this.state = AsyncHTTPClient.State.ABORTED;
AsyncHTTPClient.AbortByHandle(this.m_Handle);
}
public bool IsAborted()
{
return this.state == AsyncHTTPClient.State.ABORTED;
}
public bool IsDone()
{
return AsyncHTTPClient.IsDone(this.state);
}
public static bool IsDone(AsyncHTTPClient.State state)
{
bool result;
switch (state)
{
case AsyncHTTPClient.State.DONE_OK:
case AsyncHTTPClient.State.DONE_FAILED:
case AsyncHTTPClient.State.ABORTED:
case AsyncHTTPClient.State.TIMEOUT:
result = true;
break;
default:
result = false;
break;
}
return result;
}
public bool IsSuccess()
{
return this.state == AsyncHTTPClient.State.DONE_OK;
}
public static bool IsSuccess(AsyncHTTPClient.State state)
{
return state == AsyncHTTPClient.State.DONE_OK;
}
public void Begin()
{
if (this.IsAborted())
{
this.state = AsyncHTTPClient.State.ABORTED;
}
else
{
if (this.m_Method == "")
{
this.m_Method = "GET";
}
string[] headers = (from kv in this.header
select string.Format("{0}: {1}", kv.Key, kv.Value)).ToArray<string>();
this.m_Handle = AsyncHTTPClient.SubmitClientRequest(this.tag, this.m_ToUrl, headers, this.m_Method, this.m_FromData, new AsyncHTTPClient.RequestDoneCallback(this.Done), new AsyncHTTPClient.RequestProgressCallback(this.Progress));
}
}
private void Done(AsyncHTTPClient.State status, int i_ResponseCode)
{
this.state = status;
this.responseCode = i_ResponseCode;
if (this.doneCallback != null)
{
this.doneCallback(this);
}
this.m_Handle = (IntPtr)0;
}
private void Progress(AsyncHTTPClient.State status, int bytesDone, int bytesTotal)
{
this.state = status;
if (this.statusCallback != null)
{
this.statusCallback(status, bytesDone, bytesTotal);
}
}
private string EscapeLong(string v)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < v.Length; i += 32766)
{
stringBuilder.Append(Uri.EscapeDataString(v.Substring(i, (v.Length - i <= 32766) ? (v.Length - i) : 32766)));
}
return stringBuilder.ToString();
}
}
}