about summary refs log tree commit diff stats
path: root/src/io/request.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-02 13:13:14 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-02 13:27:06 +0200
commitb1fde40677d0cfeb5a5c28bdd0aeca775b6aa0e1 (patch)
tree4572f7d2216cc9ed03670bcee0cb6c39a4cf4936 /src/io/request.nim
parent70eccee7bcdc5486cfb339c95f8995970a2f41d1 (diff)
downloadchawan-b1fde40677d0cfeb5a5c28bdd0aeca775b6aa0e1.tar.gz
return Result[T, JSError] from fromJS
Diffstat (limited to 'src/io/request.nim')
-rw-r--r--src/io/request.nim12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/io/request.nim b/src/io/request.nim
index a5a0158f..af7daf47 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -5,7 +5,6 @@ import tables
 
 import bindings/quickjs
 import io/headers
-import js/exception
 import js/javascript
 import types/formdata
 import types/url
@@ -200,7 +199,7 @@ func newRequest*(ctx: JSContext, resource: string,
   var credentials = CredentialsMode.SAME_ORIGIN
   var mode = fallbackMode.get(RequestMode.NO_CORS)
   let hl = newHeaders()
-  var proxyUrl: Opt[URL]
+  var proxyUrl: URL
   var multipart: Opt[FormData]
   #TODO fallback mode, origin, window, request mode, ...
   if init.isSome:
@@ -210,9 +209,9 @@ func newRequest*(ctx: JSContext, resource: string,
     let bodyProp = JS_GetPropertyStr(ctx, init, "body")
     if not JS_IsNull(bodyProp) and not JS_IsUndefined(bodyProp):
       # ????
-      multipart = fromJS[FormData](ctx, bodyProp)
+      multipart = opt(fromJS[FormData](ctx, bodyProp))
       if multipart.isNone:
-        body = fromJS[string](ctx, bodyProp)
+        body = opt(fromJS[string](ctx, bodyProp))
     #TODO inputbody
     if (multipart.isSome or body.isSome) and
         httpMethod in {HTTP_GET, HTTP_HEAD}:
@@ -224,9 +223,10 @@ func newRequest*(ctx: JSContext, resource: string,
     mode = fromJS[RequestMode](ctx, JS_GetPropertyStr(ctx, init, "mode"))
       .get(mode)
     #TODO find a standard compatible way to implement this
-    proxyUrl = fromJS[URL](ctx, JS_GetPropertyStr(ctx, init, "proxyUrl"))
+    let proxyUrlProp = JS_GetPropertyStr(ctx, init, "proxyUrl")
+    proxyUrl = fromJS[URL](ctx, proxyUrlProp).get(nil)
   return ok(newRequest(url, httpMethod, hl, body, multipart, mode, credentials,
-    proxy = proxyUrl.get(nil)))
+    proxy = proxyUrl))
 
 func credentialsMode*(attribute: CORSAttribute): CredentialsMode =
   case attribute
/Makefile?id=7fae592de5beaa88bf82b497a3bf06be372d20cb'>^
9ee1dd6e ^

2dec7483 ^
fe9ac5f7 ^
ab203acf ^


b512b00d ^
fe9ac5f7 ^
053e0be9 ^
6e988941 ^
2dec7483 ^
c9337674 ^
0beb8385 ^
fe9ac5f7 ^
53bc4753 ^

4a216fe8 ^

fe9ac5f7 ^




d4409bae ^
c9337674 ^
d4409bae ^
c9337674 ^
d4409bae ^










c9337674 ^
bf761bcb ^

ae7cc86b ^
e58016bf ^

48b19713 ^
053e0be9 ^




6e988941 ^





f4d895c0 ^
1dcb9cf6 ^
ae7cc86b ^
1dcb9cf6 ^
f4d895c0 ^
e58016bf ^
ae7cc86b ^
e58016bf ^

f4d895c0 ^
1dcb9cf6 ^
48b19713 ^
1dcb9cf6 ^
2dec7483 ^
9ee1dd6e ^


fe9ac5f7 ^
9ee1dd6e ^


fe9ac5f7 ^
b512b00d ^



ab203acf ^
fc09f0be ^
53bc4753 ^
ae7cc86b ^
53bc4753 ^
ab203acf ^

0e4fe966 ^

ae7cc86b ^
53bc4753 ^
4eb57c2b ^
a6166c4d ^
ae7cc86b ^
53bc4753 ^
189e73f7 ^
ab203acf ^
d4409bae ^
df40fcdd ^
ae7cc86b ^
53bc4753 ^
a6166c4d ^
53bc4753 ^
d4409bae ^
53bc4753 ^
fc09f0be ^
ae7cc86b ^
53bc4753 ^
ab203acf ^
1df10adf ^
ab203acf ^

fc09f0be ^
53bc4753 ^
ae7cc86b ^
53bc4753 ^
ab203acf ^
bf761bcb ^
b0547ba9 ^









71a18c7f ^
aacde453 ^












4a216fe8 ^

fd8f6d7d ^

b4da6c35 ^
e901e00e ^
4a216fe8 ^

fd8f6d7d ^

fad4fb18 ^
4a216fe8 ^
04cbc981 ^
a2d276c7 ^
4a216fe8 ^
a2d276c7 ^

4a216fe8 ^

8048a943 ^
e746fcf9 ^
fe9ac5f7 ^



4a216fe8 ^

3b264751 ^
2173f509 ^
4a216fe8 ^

435882f1 ^
4a216fe8 ^
8048a943 ^
b8becdc0 ^
fe9ac5f7 ^
435882f1 ^
6b0b7ccf ^
29441535 ^
4a216fe8 ^
48b19713 ^
fe9ac5f7 ^
f9a184c2 ^
48b19713 ^
53bc4753 ^





48b19713 ^
053e0be9 ^
6e988941 ^
f4d895c0 ^

48b19713 ^
fe9ac5f7 ^
b512b00d ^
b0547ba9 ^

8048a943 ^
4a216fe8 ^






b8becdc0 ^
4a216fe8 ^
fe9ac5f7 ^
8048a943 ^
24e6e40f ^
6b0b7ccf ^
24e6e40f ^
4a216fe8 ^
fe9ac5f7 ^
f9a184c2 ^
ab203acf ^
4eb57c2b ^
189e73f7 ^
fe9ac5f7 ^
bf761bcb ^

53bc4753 ^

fe9ac5f7 ^
b512b00d ^
53bc4753 ^

053e0be9 ^
6e988941 ^
53bc4753 ^
b0547ba9 ^

53bc4753 ^
4a216fe8 ^




b8becdc0 ^
4a216fe8 ^
fe9ac5f7 ^
6b0b7ccf ^



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