diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index 2a34b9a46..dc7b9b084 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -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; } @@ -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 { @@ -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( @@ -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 { @@ -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; } @@ -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]); @@ -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); }