diff --git a/lib/include/duckdb/web/config.h b/lib/include/duckdb/web/config.h index 935c71e95..d11d0dc97 100644 --- a/lib/include/duckdb/web/config.h +++ b/lib/include/duckdb/web/config.h @@ -11,6 +11,8 @@ namespace duckdb { namespace web { +extern std::string experimental_s3_tables_global_proxy; + enum WebDBFeature : uint32_t { FAST_EXCEPTIONS = 0, THREADS = 1, diff --git a/lib/src/http_wasm.cc b/lib/src/http_wasm.cc index 036606827..2a34b9a46 100644 --- a/lib/src/http_wasm.cc +++ b/lib/src/http_wasm.cc @@ -5,6 +5,7 @@ #include #include "duckdb/common/http_util.hpp" +#include "duckdb/web/config.h" namespace duckdb { class HTTPLogger; @@ -22,6 +23,17 @@ class HTTPWasmClient : public HTTPClient { string path = host_port + info.url; path = info.url; + if (!web::experimental_s3_tables_global_proxy.empty()) { + if (info.url.rfind(web::experimental_s3_tables_global_proxy, 0) != 0) { + auto id_table = path.find("--table-s3.s3."); + auto id_aws = path.find(".amazonaws.com/"); + if (id_table != std::string::npos && id_aws != std::string::npos && id_table < id_aws) { + path = web::experimental_s3_tables_global_proxy + path.substr(8); + } + } + } else { + path = "https://" + path; + } int n = 0; for (auto h : info.headers) { @@ -66,6 +78,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 { @@ -124,9 +137,7 @@ class HTTPWasmClient : public HTTPClient { if (!exe) { res = make_uniq(HTTPStatusCode::NotFound_404); - res->reason = - "Unknown error, something went wrong in Wasm land! Please consult the console and consider reporting a " - "bug"; + res->reason = "Please consult the browser console for details, might be potentially a CORS error"; } else { res = duckdb::make_uniq(HTTPStatusCode::OK_200); uint64_t LEN = 0; @@ -256,9 +267,7 @@ class HTTPWasmClient : public HTTPClient { if (!exe) { res = make_uniq(HTTPStatusCode::NotFound_404); - res->reason = - "Unknown error, something went wrong in Wasm land! Please consult the console and consider reporting a " - "bug"; + res->reason = "Please consult the browser console for details, might be potentially a CORS error"; } else { res = duckdb::make_uniq(HTTPStatusCode::OK_200); uint64_t LEN = 0; @@ -343,8 +352,10 @@ class HTTPWasmClient : public HTTPClient { i += 2; } +xhr.setRequestHeader("Content-Type", "application/octet-stream"); try { - xhr.send(UTF8ToString($4)); + xhr.send(new Uint8Array(0)); + // xhr.send(UTF8ToString($4)); } catch { return 0; } @@ -389,9 +400,7 @@ class HTTPWasmClient : public HTTPClient { if (!exe) { res = make_uniq(HTTPStatusCode::NotFound_404); - res->reason = - "Unknown error, something went wrong in Wasm land! Please consult the console and consider reporting a " - "bug"; + res->reason = "Please consult the browser console for details, might be potentially a CORS error"; } else { res = duckdb::make_uniq(HTTPStatusCode::OK_200); uint64_t LEN = 0; @@ -409,7 +418,7 @@ class HTTPWasmClient : public HTTPClient { info.content_handler((const unsigned char *)exe + 4, LEN); } */ - + // info.buffer_out += string(exe+4, LEN); free(exe); } diff --git a/lib/src/webdb.cc b/lib/src/webdb.cc index f5e5b9cca..f02bf4014 100644 --- a/lib/src/webdb.cc +++ b/lib/src/webdb.cc @@ -75,6 +75,7 @@ namespace duckdb { bool preloaded_httpfs{true}; +string web::experimental_s3_tables_global_proxy{""}; namespace web { @@ -792,6 +793,10 @@ void WebDB::RegisterCustomExtensionOptions(shared_ptr database) webfs->Config()->duckdb_config_options.reliable_head_requests = BooleanValue::Get(parameter); webfs->IncrementCacheEpoch(); }; + auto callback_experimental_s3_tables_global_proxy = [](ClientContext& context, SetScope scope, + Value& parameter) { + experimental_s3_tables_global_proxy = StringValue::Get(parameter); + }; config.AddExtensionOption("builtin_httpfs", "Use built-in HTTPS support", LogicalType::BOOLEAN, false, callback_builtin_httpfs); @@ -806,6 +811,9 @@ void WebDB::RegisterCustomExtensionOptions(shared_ptr database) Value(), callback_s3_endpoint); config.AddExtensionOption("reliable_head_requests", "Set whether HEAD requests returns reliable content-length", LogicalType::BOOLEAN, Value(true), callback_reliable_head_requests); + config.AddExtensionOption("experimental_s3_tables_global_proxy", + "Experimental - Global proxy to interact with S3 Tables", LogicalType::VARCHAR, + Value(""), callback_experimental_s3_tables_global_proxy); webfs->IncrementCacheEpoch(); }