From 914509164911c9558dac50ccadb4eb1e0769be96 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 27 Aug 2025 11:08:50 +0200 Subject: [PATCH 1/5] Improve building path --- lib/src/http_wasm.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index 2a34b9a46..8b43892d5 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; } From 9647476b22c201d5bf0a14be76dc2d013dbfced3 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 27 Aug 2025 11:09:22 +0200 Subject: [PATCH 2/5] HTTPWasmClient: Avoid setting User-Agent --- lib/src/http_wasm.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index 8b43892d5..c140ee65d 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -210,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 { @@ -341,6 +342,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 { From 2d051284a85ca93ca7c40a420746b1eece311535 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 27 Aug 2025 11:09:46 +0200 Subject: [PATCH 3/5] HTTPWasmClient: POST, correctly pass down payload --- lib/src/http_wasm.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index c140ee65d..a145f4875 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -318,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( @@ -355,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; } @@ -389,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]); From 973e62330bdf6f3a6b2874b7f8a932b91b73b52e Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 27 Aug 2025 11:10:06 +0200 Subject: [PATCH 4/5] HTTPWasmCLient: Fixup post --- lib/src/http_wasm.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index a145f4875..e7e9dc1b8 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -427,12 +427,13 @@ class HTTPWasmClient : public HTTPClient { LEN *= 256; LEN += ((uint8_t *)exe)[0]; res->body = string(exe + 4, LEN); - /* - if (info.content_handler) { + + /* + 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); } From 035803f935b0459806e41b79d1fd82bc5ef8651f Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 27 Aug 2025 11:23:08 +0200 Subject: [PATCH 5/5] Formatting --- lib/src/http_wasm.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index e7e9dc1b8..dc7b9b084 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -318,9 +318,9 @@ 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); + 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; @@ -401,7 +401,7 @@ class HTTPWasmClient : public HTTPClient { path.c_str(), n, z, "POST", payload, buffer_length); // clang-format on - free(payload); + free(payload); i = 0; for (auto h : info.headers) { @@ -427,13 +427,9 @@ class HTTPWasmClient : public HTTPClient { 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); }