@@ -37,7 +37,7 @@ class HTTPWasmClient : public HTTPClient {
37
37
memcpy (z[i], h.first .c_str (), h.first .size ());
38
38
i++;
39
39
z[i] = (char *)malloc (h.second .size () * 4 + 1 );
40
- memset (z[i], 0 , h.first .size () * 4 + 1 );
40
+ memset (z[i], 0 , h.second .size () * 4 + 1 );
41
41
memcpy (z[i], h.second .c_str (), h.second .size ());
42
42
i++;
43
43
}
@@ -51,17 +51,27 @@ class HTTPWasmClient : public HTTPClient {
51
51
return 0 ;
52
52
}
53
53
const xhr = new XMLHttpRequest ();
54
+ if (false && url.startsWith (" http://" )) {
55
+ url = " https://" + url.substr (7 );
56
+ }
54
57
xhr.open (UTF8ToString ($3 ), url, false );
55
58
xhr.responseType = " arraybuffer" ;
56
59
57
60
var i = 0 ;
58
61
var len = $1 ;
59
- while (i < len) {
60
- var ptr1 = HEAP32[($2 + (i * 4 )) >> 2 ];
61
- var ptr2 = HEAP32[($2 + (( i + 1 ) * 4 )) >> 2 ];
62
+ while (i < len* 2 ) {
63
+ var ptr1 = HEAP32[($2 )/ 4 + i ];
64
+ var ptr2 = HEAP32[($2 )/ 4 + i + 1 ];
62
65
63
66
try {
64
- xhr.setRequestHeader (encodeURI (UTF8ToString (ptr1)), encodeURI (UTF8ToString (ptr2)));
67
+ var z = encodeURI (UTF8ToString (ptr1));
68
+ if (z === " Host" ) z = " X-Host-Override" ;
69
+ if (z === " Authorization" ) {
70
+ xhr.setRequestHeader (z, UTF8ToString (ptr2));
71
+ } else {
72
+
73
+ xhr.setRequestHeader (z, encodeURI (UTF8ToString (ptr2)));
74
+ }
65
75
} catch (error) {
66
76
console.warn (" Error while performing XMLHttpRequest.setRequestHeader()" , error);
67
77
}
@@ -134,12 +144,12 @@ class HTTPWasmClient : public HTTPClient {
134
144
info.content_handler ((const unsigned char *)exe + 4 , LEN);
135
145
}
136
146
137
- free (exe);
147
+ free (exe);
138
148
}
139
149
140
150
return res;
141
151
}
142
- unique_ptr<HTTPResponse> Post (PostRequestInfo &info) override {
152
+ unique_ptr<HTTPResponse> Head (HeadRequestInfo &info) override {
143
153
unique_ptr<HTTPResponse> res;
144
154
145
155
string path = host_port + info.url ;
@@ -159,7 +169,7 @@ class HTTPWasmClient : public HTTPClient {
159
169
memcpy (z[i], h.first .c_str (), h.first .size ());
160
170
i++;
161
171
z[i] = (char *)malloc (h.second .size () * 4 + 1 );
162
- memset (z[i], 0 , h.first .size () * 4 + 1 );
172
+ memset (z[i], 0 , h.second .size () * 4 + 1 );
163
173
memcpy (z[i], h.second .c_str (), h.second .size ());
164
174
i++;
165
175
}
@@ -173,29 +183,39 @@ class HTTPWasmClient : public HTTPClient {
173
183
return 0 ;
174
184
}
175
185
const xhr = new XMLHttpRequest ();
186
+ if (false && url.startsWith (" http://" )) {
187
+ url = " https://" + url.substr (7 );
188
+ }
176
189
xhr.open (UTF8ToString ($3 ), url, false );
177
190
xhr.responseType = " arraybuffer" ;
178
191
179
192
var i = 0 ;
180
193
var len = $1 ;
181
- while (i < len) {
182
- var ptr1 = HEAP32[($2 + (i * 4 )) >> 2 ];
183
- var ptr2 = HEAP32[($2 + (( i + 1 ) * 4 )) >> 2 ];
194
+ while (i < len* 2 ) {
195
+ var ptr1 = HEAP32[($2 )/ 4 + i ];
196
+ var ptr2 = HEAP32[($2 )/ 4 + i + 1 ];
184
197
185
198
try {
186
- xhr.setRequestHeader (encodeURI (UTF8ToString (ptr1)), encodeURI (UTF8ToString (ptr2)));
199
+ var z = encodeURI (UTF8ToString (ptr1));
200
+ if (z === " Host" ) z = " X-Host-Override" ;
201
+ if (z === " Authorization" ) {
202
+ xhr.setRequestHeader (z, UTF8ToString (ptr2));
203
+ } else {
204
+
205
+ xhr.setRequestHeader (z, encodeURI (UTF8ToString (ptr2)));
206
+ }
187
207
} catch (error) {
188
208
console.warn (" Error while performing XMLHttpRequest.setRequestHeader()" , error);
189
209
}
190
210
i += 2 ;
191
211
}
192
212
193
213
try {
194
- xhr.send (UTF8ToString ($ 4 ) );
214
+ xhr.send (null );
195
215
} catch {
196
216
return 0 ;
197
217
}
198
- if (xhr.status != 200 ) return 0 ;
218
+ if (xhr.status >= 400 ) return 0 ;
199
219
var uInt8Array = xhr.response ;
200
220
201
221
var len = uInt8Array.byteLength ;
@@ -222,7 +242,8 @@ class HTTPWasmClient : public HTTPClient {
222
242
Module.HEAPU8 .set (LEN123, fileOnWasmHeap);
223
243
return fileOnWasmHeap;
224
244
},
225
- path.c_str (), n, z, " POST" , info.buffer_in );
245
+ path.c_str (), n, z, " HEAD" );
246
+ // clang-format on
226
247
227
248
i = 0 ;
228
249
for (auto h : info.headers ) {
@@ -236,8 +257,8 @@ class HTTPWasmClient : public HTTPClient {
236
257
if (!exe) {
237
258
res = make_uniq<HTTPResponse>(HTTPStatusCode::NotFound_404);
238
259
res->reason =
239
- " Unknown error, something went quack in Wasm land! Please consult the console and or the docs at "
240
- " https://duckdb.org/community_extensions/extensions/webmacro " ;
260
+ " Unknown error, something went wrong in Wasm land! Please consult the console and consider reporting a "
261
+ " bug " ;
241
262
} else {
242
263
res = duckdb::make_uniq<HTTPResponse>(HTTPStatusCode::OK_200);
243
264
uint64_t LEN = 0 ;
@@ -250,15 +271,18 @@ class HTTPWasmClient : public HTTPClient {
250
271
LEN *= 256 ;
251
272
LEN += ((uint8_t *)exe)[0 ];
252
273
res->body = string (exe + 4 , LEN);
253
- free (exe);
274
+ /*
275
+ if (info.content_handler) {
276
+ info.content_handler((const unsigned char *)exe + 4, LEN);
277
+ }
278
+ */
279
+
280
+ free (exe);
254
281
}
255
- // clang-format on
256
282
257
283
return res;
258
284
}
259
- unique_ptr<HTTPResponse> Put (PutRequestInfo &info) override { return nullptr ; }
260
-
261
- unique_ptr<HTTPResponse> Head (HeadRequestInfo &info) override {
285
+ unique_ptr<HTTPResponse> Post (PostRequestInfo &info) override {
262
286
unique_ptr<HTTPResponse> res;
263
287
264
288
string path = host_port + info.url ;
@@ -278,7 +302,7 @@ class HTTPWasmClient : public HTTPClient {
278
302
memcpy (z[i], h.first .c_str (), h.first .size ());
279
303
i++;
280
304
z[i] = (char *)malloc (h.second .size () * 4 + 1 );
281
- memset (z[i], 0 , h.first .size () * 4 + 1 );
305
+ memset (z[i], 0 , h.second .size () * 4 + 1 );
282
306
memcpy (z[i], h.second .c_str (), h.second .size ());
283
307
i++;
284
308
}
@@ -292,29 +316,39 @@ class HTTPWasmClient : public HTTPClient {
292
316
return 0 ;
293
317
}
294
318
const xhr = new XMLHttpRequest ();
319
+ if (false && url.startsWith (" http://" )) {
320
+ url = " https://" + url.substr (7 );
321
+ }
295
322
xhr.open (UTF8ToString ($3 ), url, false );
296
323
xhr.responseType = " arraybuffer" ;
297
324
298
325
var i = 0 ;
299
326
var len = $1 ;
300
- while (i < len) {
301
- var ptr1 = HEAP32[($2 + (i * 4 )) >> 2 ];
302
- var ptr2 = HEAP32[($2 + (( i + 1 ) * 4 )) >> 2 ];
327
+ while (i < len* 2 ) {
328
+ var ptr1 = HEAP32[($2 )/ 4 + i ];
329
+ var ptr2 = HEAP32[($2 )/ 4 + i + 1 ];
303
330
304
331
try {
305
- xhr.setRequestHeader (encodeURI (UTF8ToString (ptr1)), encodeURI (UTF8ToString (ptr2)));
332
+ var z = encodeURI (UTF8ToString (ptr1));
333
+ if (z === " Host" ) z = " X-Host-Override" ;
334
+ if (z === " Authorization" ) {
335
+ xhr.setRequestHeader (z, UTF8ToString (ptr2));
336
+ } else {
337
+
338
+ xhr.setRequestHeader (z, encodeURI (UTF8ToString (ptr2)));
339
+ }
306
340
} catch (error) {
307
341
console.warn (" Error while performing XMLHttpRequest.setRequestHeader()" , error);
308
342
}
309
343
i += 2 ;
310
344
}
311
345
312
346
try {
313
- xhr.send (null );
347
+ xhr.send (UTF8ToString ($ 4 ) );
314
348
} catch {
315
349
return 0 ;
316
350
}
317
- if (xhr.status != 200 ) return 0 ;
351
+ if (xhr.status >= 400 ) return 0 ;
318
352
var uInt8Array = xhr.response ;
319
353
320
354
var len = uInt8Array.byteLength ;
@@ -341,7 +375,7 @@ class HTTPWasmClient : public HTTPClient {
341
375
Module.HEAPU8 .set (LEN123, fileOnWasmHeap);
342
376
return fileOnWasmHeap;
343
377
},
344
- path.c_str (), n, z, " HEAD " );
378
+ path.c_str (), n, z, " POST " , info. buffer_in );
345
379
// clang-format on
346
380
347
381
i = 0 ;
@@ -370,11 +404,17 @@ class HTTPWasmClient : public HTTPClient {
370
404
LEN *= 256 ;
371
405
LEN += ((uint8_t *)exe)[0 ];
372
406
res->body = string (exe + 4 , LEN);
373
- free (exe);
407
+ /*
408
+ if (info.content_handler) {
409
+ info.content_handler((const unsigned char *)exe + 4, LEN);
410
+ }
411
+ */
412
+ free (exe);
374
413
}
375
414
376
415
return res;
377
416
}
417
+ unique_ptr<HTTPResponse> Put (PutRequestInfo &info) override { return nullptr ; }
378
418
unique_ptr<HTTPResponse> Delete (DeleteRequestInfo &info) override { return nullptr ; }
379
419
380
420
private:
0 commit comments