FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ICP.NET/UnityAssets/UnityHttp.cs at SendSignedContent · edjCase/ICP.NET · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
edjCase
/
ICP.NET
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
55
Code
Issues
6
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ICP.NET
/
UnityAssets
/
UnityHttp.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (77 loc) · 2.21 KB
Breadcrumbs
ICP.NET
/
UnityAssets
/
UnityHttp.cs
Copy path
File metadata and controls
92 lines (77 loc) · 2.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
EdjCase
.
ICP
.
Agent
.
Agents
.
Http
;
using
System
;
using
System
.
Net
;
using
System
.
Runtime
.
CompilerServices
;
using
System
.
Threading
;
using
System
.
Threading
.
Tasks
;
using
UnityEngine
;
using
UnityEngine
.
Networking
;
public
class
UnityHttpClient
:
IHttpClient
{
public
async
Task
<
HttpResponse
>
GetAsync
(
string
url
,
CancellationToken
?
cancellationToken
=
null
)
{
using
(
UnityWebRequest
request
=
UnityWebRequest
.
Get
(
GetUri
(
url
)
)
)
{
await
request
.
SendWebRequest
(
)
;
return
ParseResponse
(
request
)
;
}
}
public
async
Task
<
HttpResponse
>
PostAsync
(
string
url
,
byte
[
]
cborBody
,
CancellationToken
?
cancellationToken
=
null
)
{
using
(
UnityWebRequest
request
=
new
(
)
)
{
request
.
method
=
"POST"
;
request
.
uri
=
GetUri
(
url
)
;
request
.
downloadHandler
=
new
DownloadHandlerBuffer
(
)
;
request
.
uploadHandler
=
new
UploadHandlerRaw
(
cborBody
)
;
request
.
uploadHandler
.
contentType
=
"application/cbor"
;
await
request
.
SendWebRequest
(
)
;
return
ParseResponse
(
request
)
;
}
}
private
static
Uri
GetUri
(
string
path
)
{
if
(
!
path
.
StartsWith
(
"/"
)
)
{
path
=
"/"
+
path
;
}
return
new
Uri
(
"https://ic0.app"
+
path
)
;
}
private
static
HttpResponse
ParseResponse
(
UnityWebRequest
request
)
{
if
(
request
.
result
!=
UnityWebRequest
.
Result
.
Success
)
{
throw
new
Exception
(
"Failed UnityWebRequest: "
+
request
.
error
)
;
}
HttpStatusCode
statusCode
=
(
HttpStatusCode
)
request
.
responseCode
;
byte
[
]
data
=
request
.
downloadHandler
.
data
;
return
new
HttpResponse
(
statusCode
,
(
)
=>
Task
.
FromResult
(
data
)
)
;
}
}
internal
class
UnityWebRequestAwaiter
:
INotifyCompletion
{
private
UnityWebRequestAsyncOperation
asyncOp
;
private
Action
continuation
;
public
UnityWebRequestAwaiter
(
UnityWebRequestAsyncOperation
asyncOp
)
{
this
.
asyncOp
=
asyncOp
;
asyncOp
.
completed
+=
OnRequestCompleted
;
}
public
bool
IsCompleted
{
get
{
return
asyncOp
.
isDone
;
}
}
public
void
GetResult
(
)
{
}
public
void
OnCompleted
(
Action
continuation
)
{
this
.
continuation
=
continuation
;
}
private
void
OnRequestCompleted
(
AsyncOperation
obj
)
{
continuation
(
)
;
}
}
internal
static
class
ExtensionMethods
{
public
static
UnityWebRequestAwaiter
GetAwaiter
(
this
UnityWebRequestAsyncOperation
asyncOp
)
{
return
new
UnityWebRequestAwaiter
(
asyncOp
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL