Skip to content

Commit 9497e1b

Browse files
authored
Merge pull request #80 from carlopi/httpfs_client_implementation
Add httpfs_client_implementation option, currently only `default` and `httplib` are valid
2 parents c93303d + 581889c commit 9497e1b

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

extension/httpfs/httpfs_extension.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212

1313
namespace duckdb {
1414

15+
static void SetHttpfsClientImplementation(DBConfig &config, const string &value) {
16+
if (config.http_util && config.http_util->GetName() == "WasmHTTPUtils") {
17+
if (value == "wasm" || value == "default") {
18+
// Already handled, do not override
19+
return;
20+
}
21+
throw InvalidInputException("Unsupported option for httpfs_client_implementation, only `wasm` and "
22+
"`default` are currently supported for duckdb-wasm");
23+
}
24+
if (value == "httplib" || value == "default") {
25+
if (!config.http_util || config.http_util->GetName() != "HTTPFSUtil") {
26+
config.http_util = make_shared_ptr<HTTPFSUtil>();
27+
}
28+
return;
29+
}
30+
throw InvalidInputException("Unsupported option for httpfs_client_implementation, only `curl`, `httplib` and "
31+
"`default` are currently supported");
32+
}
33+
1534
static void LoadInternal(DatabaseInstance &instance) {
1635
auto &fs = instance.GetFileSystem();
1736

@@ -64,11 +83,16 @@ static void LoadInternal(DatabaseInstance &instance) {
6483
config.AddExtensionOption("hf_max_per_page", "Debug option to limit number of items returned in list requests",
6584
LogicalType::UBIGINT, Value::UBIGINT(0));
6685

67-
if (config.http_util && config.http_util->GetName() == "WasmHTTPUtils") {
68-
// Already handled, do not override
69-
} else {
70-
config.http_util = make_shared_ptr<HTTPFSUtil>();
71-
}
86+
auto callback_httpfs_client_implementation = [](ClientContext &context, SetScope scope, Value &parameter) {
87+
auto &config = DBConfig::GetConfig(context);
88+
string value = StringValue::Get(parameter);
89+
SetHttpfsClientImplementation(config, value);
90+
};
91+
92+
config.AddExtensionOption("httpfs_client_implementation", "Select which is the HTTPUtil implementation to be used",
93+
LogicalType::VARCHAR, "default", callback_httpfs_client_implementation);
94+
95+
SetHttpfsClientImplementation(config, "default");
7296

7397
auto provider = make_uniq<AWSEnvironmentCredentialsProvider>(config);
7498
provider->SetAll();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# name: test/sql/htpfs_client/httpfs_client_implementation.test
2+
# description: Tests basic valus for httpfs_client_implementation
3+
# group: [httpfs_client]
4+
5+
require httpfs
6+
7+
statement ok
8+
set httpfs_client_implementation = 'default';
9+
10+
statement ok
11+
set httpfs_client_implementation = 'httplib';
12+
13+
statement error
14+
set httpfs_client_implementation = 'something else';
15+
----
16+
Unsupported option for httpfs_client_implementation

0 commit comments

Comments
 (0)