Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib/include/duckdb/web/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 20 additions & 11 deletions lib/src/http_wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>

#include "duckdb/common/http_util.hpp"
#include "duckdb/web/config.h"

namespace duckdb {
class HTTPLogger;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -124,9 +137,7 @@ class HTTPWasmClient : public HTTPClient {

if (!exe) {
res = make_uniq<HTTPResponse>(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<HTTPResponse>(HTTPStatusCode::OK_200);
uint64_t LEN = 0;
Expand Down Expand Up @@ -256,9 +267,7 @@ class HTTPWasmClient : public HTTPClient {

if (!exe) {
res = make_uniq<HTTPResponse>(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<HTTPResponse>(HTTPStatusCode::OK_200);
uint64_t LEN = 0;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -389,9 +400,7 @@ class HTTPWasmClient : public HTTPClient {

if (!exe) {
res = make_uniq<HTTPResponse>(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<HTTPResponse>(HTTPStatusCode::OK_200);
uint64_t LEN = 0;
Expand All @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/src/webdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
namespace duckdb {

bool preloaded_httpfs{true};
string web::experimental_s3_tables_global_proxy{""};

namespace web {

Expand Down Expand Up @@ -792,6 +793,10 @@ void WebDB::RegisterCustomExtensionOptions(shared_ptr<duckdb::DuckDB> 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);
Expand All @@ -806,6 +811,9 @@ void WebDB::RegisterCustomExtensionOptions(shared_ptr<duckdb::DuckDB> 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();
}
Expand Down