Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions lib/src/http_wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class HTTPWasmClient : public HTTPClient {
path = web::experimental_s3_tables_global_proxy + path.substr(8);
}
}
} else {
}
if (path.rfind("https://", 0 != 0)) {
path = "https://" + path;
}

Expand Down Expand Up @@ -209,6 +210,7 @@ class HTTPWasmClient : public HTTPClient {
try {
var z = encodeURI(UTF8ToString(ptr1));
if (z === "Host") z = "X-Host-Override";
if (z === "User-Agent") z = "X-user-agent";
if (z === "Authorization") {
xhr.setRequestHeader(z, UTF8ToString(ptr2));
} else {
Expand Down Expand Up @@ -316,6 +318,10 @@ class HTTPWasmClient : public HTTPClient {
i++;
}

const int buffer_length = info.buffer_in_len;
char *payload = (char *)malloc(buffer_length);
memcpy(payload, info.buffer_in, buffer_length);

// clang-format off
char *exe = NULL;
exe = (char *)EM_ASM_PTR(
Expand All @@ -340,6 +346,7 @@ class HTTPWasmClient : public HTTPClient {
try {
var z = encodeURI(UTF8ToString(ptr1));
if (z === "Host") z = "X-Host-Override";
if (z === "User-Agent") z = "X-user-agent";
if (z === "Authorization") {
xhr.setRequestHeader(z, UTF8ToString(ptr2));
} else {
Expand All @@ -352,10 +359,15 @@ class HTTPWasmClient : public HTTPClient {
i += 2;
}

xhr.setRequestHeader("Content-Type", "application/octet-stream");
//xhr.setRequestHeader("Content-Type", "application/octet-stream");
//xhr.setRequestHeader("Content-Type", "text/json");
try {
xhr.send(new Uint8Array(0));
// xhr.send(UTF8ToString($4));
var post_payload = new Uint8Array($5);

for (var iii = 0; iii < $5; iii++) {
post_payload[iii] = Module.HEAPU8[iii + $4];
}
xhr.send(post_payload);
} catch {
return 0;
}
Expand Down Expand Up @@ -386,9 +398,11 @@ xhr.setRequestHeader("Content-Type", "application/octet-stream");
Module.HEAPU8.set(LEN123, fileOnWasmHeap);
return fileOnWasmHeap;
},
path.c_str(), n, z, "POST", info.buffer_in);
path.c_str(), n, z, "POST", payload, buffer_length);
// clang-format on

free(payload);

i = 0;
for (auto h : info.headers) {
free(z[i]);
Expand All @@ -413,12 +427,9 @@ xhr.setRequestHeader("Content-Type", "application/octet-stream");
LEN *= 256;
LEN += ((uint8_t *)exe)[0];
res->body = string(exe + 4, LEN);
/*
if (info.content_handler) {
info.content_handler((const unsigned char *)exe + 4, LEN);
}
*/
// info.buffer_out += string(exe+4, LEN);

info.buffer_out += string(exe + 4, LEN);

free(exe);
}

Expand Down