Skip to content

Use curl as optional client #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
29052b3
include open ssl
Tmonster May 14, 2025
180bcb6
attempt to overwrite get
Tmonster May 15, 2025
303c9a7
compiles with curl now
Tmonster May 15, 2025
b8272b1
put head delete post get replaced
Tmonster May 16, 2025
e6c2780
bump duckdb
Tmonster May 16, 2025
2afdc88
remove extension stuff
Tmonster May 16, 2025
be81a80
install curl during build
Tmonster May 16, 2025
fdac277
run on ubuntu-latest
Tmonster May 16, 2025
ef581de
init vcpackage toolchain path
Tmonster May 16, 2025
e7bc7e0
actually add params to end of url for get requests
Tmonster May 16, 2025
b74abc2
get the response error message as well from the http response code he…
Tmonster May 16, 2025
88f96fc
remove all running httplib.hpp code
Tmonster May 16, 2025
04cb2a8
add back in state initialization
Tmonster May 16, 2025
02e8ac1
remove output result
Tmonster May 16, 2025
c92998c
add json read test
Tmonster May 16, 2025
fa93e10
add core extensions var
Tmonster May 16, 2025
499de90
always add headers, and set many more curl options on initialize
Tmonster May 16, 2025
9d8f71e
update extension ci tools
Tmonster May 16, 2025
e0cce43
fix test add comments
Tmonster May 19, 2025
9b90587
declare header object on heap not on stack
Tmonster May 20, 2025
5b3d988
also uniq string
Tmonster May 20, 2025
ccbf00a
some more debugging statements
Tmonster May 20, 2025
de6d606
move a lot of the request response info to the heap so it does not ge…
Tmonster May 20, 2025
0c167fd
this should work on the build now
Tmonster May 20, 2025
5d8d79f
more clean up
Tmonster May 20, 2025
d901fc4
Merge branch 'main' into use_curl_as_client
Tmonster May 20, 2025
0c42015
call curl_global_init, unsure when to call cleanup
Tmonster May 20, 2025
bd44ff2
remove verbose
Tmonster May 20, 2025
3da7bff
reuse many components
Tmonster May 21, 2025
198288e
add test to check response headers
Tmonster May 21, 2025
0f9f749
remove internal exception if certificate authority cannot be set
Tmonster May 21, 2025
73103b1
fix test
Tmonster May 21, 2025
afb0c2a
actually fix test
Tmonster May 21, 2025
4b32d40
remove rogue pragma
Tmonster May 21, 2025
37e253c
Merge branch 'main' into use_curl_as_client
Tmonster May 23, 2025
07a7afa
re-run CI for after release
Tmonster May 26, 2025
db6001f
Merge branch 'main' into use_curl_as_client
Tmonster Jun 17, 2025
3a93b42
update main distribution pipeline
Tmonster Jun 17, 2025
3251e7c
Override http_util only if not already named 'WasmHTTPUtils'
carlopi Jul 2, 2025
4548495
Extract some code to hash_functions.cpp/hpp
carlopi Jul 2, 2025
ae7230f
Feature select: no crytpo.cpp and no override of encryption_utils in …
carlopi Jul 2, 2025
bb583db
Bundle-in mbedtls
carlopi Jun 18, 2025
9bf98ef
Re-enable wasm compilation
carlopi Jul 2, 2025
104bec6
Skip conditionally also httpfs_client.cpp
carlopi Jul 3, 2025
a2cc411
Separate minimal HTTPFSUtil implementations into httpfs_client and ht…
carlopi Jul 3, 2025
6f07684
Merge remote-tracking branch 'origin/main' into use_curl_as_client
carlopi Jul 3, 2025
95567d3
Have curl and httplib implementation convive side-by-side
carlopi Jul 3, 2025
9a94a7b
Merge branch 'wasm_httputil_on_main' into use_curl_as_client
carlopi Jul 3, 2025
401ff6b
Adapt test
carlopi Jul 3, 2025
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: 0 additions & 2 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
extension_name: httpfs
duckdb_version: v1.3-ossivalis
ci_tools_version: main
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads'


duckdb-stable-deploy:
Expand All @@ -32,4 +31,3 @@ jobs:
duckdb_version: v1.3-ossivalis
ci_tools_version: main
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads'
4 changes: 3 additions & 1 deletion .github/workflows/MinioTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ defaults:
jobs:
minio-tests:
name: Minio Tests
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
env:
S3_TEST_SERVER_AVAILABLE: 1
AWS_DEFAULT_REGION: eu-west-1
AWS_ACCESS_KEY_ID: minio_duckdb_user
AWS_SECRET_ACCESS_KEY: minio_duckdb_user_password
DUCKDB_S3_ENDPOINT: duckdb-minio.com:9000
DUCKDB_S3_USE_SSL: false
CORE_EXTENSIONS: 'parquet;json'
GEN: ninja
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
VCPKG_TARGET_TRIPLET: x64-linux

steps:
Expand Down
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ add_extension_definitions()
include_directories(extension/httpfs/include
${DUCKDB_MODULE_BASE_DIR}/third_party/httplib)

if (NOT EMSCRIPTEN)
set(EXTRA_SOURCES extension/httpfs/crypto.cpp extension/httpfs/httpfs_httplib_client.cpp extension/httpfs/httpfs_curl_client.cpp)
add_definitions(-DOVERRIDE_ENCRYPTION_UTILS=1)
else()
set(EXTRA_SOURCES extension/httpfs/httpfs_client_wasm.cpp)
endif()

build_static_extension(
httpfs
extension/httpfs/hffs.cpp
extension/httpfs/s3fs.cpp
extension/httpfs/httpfs.cpp
extension/httpfs/httpfs_client.cpp
extension/httpfs/http_state.cpp
extension/httpfs/crypto.cpp
extension/httpfs/hash_functions.cpp
extension/httpfs/create_secret_functions.cpp
extension/httpfs/httpfs_extension.cpp)
extension/httpfs/httpfs_extension.cpp
${EXTRA_SOURCES} )

set(PARAMETERS "-warnings")
build_loadable_extension(
Expand All @@ -27,32 +35,41 @@ build_loadable_extension(
extension/httpfs/hffs.cpp
extension/httpfs/s3fs.cpp
extension/httpfs/httpfs.cpp
extension/httpfs/httpfs_client.cpp
extension/httpfs/http_state.cpp
extension/httpfs/crypto.cpp
extension/httpfs/hash_functions.cpp
extension/httpfs/create_secret_functions.cpp
extension/httpfs/httpfs_extension.cpp)
extension/httpfs/httpfs_extension.cpp
${EXTRA_SOURCES} )

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()

find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${CURL_INCLUDE_DIRS})
if(EMSCRIPTEN)

else()
target_link_libraries(httpfs_loadable_extension duckdb_mbedtls
${OPENSSL_LIBRARIES})
target_link_libraries(httpfs_extension duckdb_mbedtls ${OPENSSL_LIBRARIES})

# Link dependencies into extension
target_link_libraries(httpfs_loadable_extension ${CURL_LIBRARIES})
target_link_libraries(httpfs_extension ${CURL_LIBRARIES})


if(MINGW)
find_package(ZLIB)
target_link_libraries(httpfs_loadable_extension ZLIB::ZLIB -lcrypt32)
target_link_libraries(httpfs_extension ZLIB::ZLIB -lcrypt32)
endif()
endif()


install(
TARGETS httpfs_extension
EXPORT "${DUCKDB_EXPORT_SET}"
Expand Down
32 changes: 10 additions & 22 deletions extension/httpfs/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
#include "crypto.hpp"
#include "hash_functions.hpp"
#include "mbedtls_wrapper.hpp"
#include <iostream>
#include "duckdb/common/common.hpp"
#include <stdio.h>

#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.hpp"

namespace duckdb {
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <openssl/rand.h>

void sha256(const char *in, size_t in_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::ComputeSha256Hash(in, in_len, (char *)out);
}
#if defined(_WIN32) && defined(OPENSSL_USE_APPLINK)
#include <openssl/applink.c>
#endif

void hmac256(const std::string &message, const char *secret, size_t secret_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::Hmac256(secret, secret_len, message.data(), message.size(), (char *)out);
}

void hmac256(std::string message, hash_bytes secret, hash_bytes &out) {
hmac256(message, (char *)secret, sizeof(hash_bytes), out);
}

void hex256(hash_bytes &in, hash_str &out) {
const char *hex = "0123456789abcdef";
unsigned char *pin = in;
unsigned char *pout = out;
for (; pin < in + sizeof(in); pout += 2, pin++) {
pout[0] = hex[(*pin >> 4) & 0xF];
pout[1] = hex[*pin & 0xF];
}
}
namespace duckdb {

AESStateSSL::AESStateSSL(const std::string *key) : context(EVP_CIPHER_CTX_new()) {
if (!(context)) {
Expand Down
28 changes: 28 additions & 0 deletions extension/httpfs/hash_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "mbedtls_wrapper.hpp"
#include "hash_functions.hpp"

namespace duckdb {

void sha256(const char *in, size_t in_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::ComputeSha256Hash(in, in_len, (char *)out);
}

void hmac256(const std::string &message, const char *secret, size_t secret_len, hash_bytes &out) {
duckdb_mbedtls::MbedTlsWrapper::Hmac256(secret, secret_len, message.data(), message.size(), (char *)out);
}

void hmac256(std::string message, hash_bytes secret, hash_bytes &out) {
hmac256(message, (char *)secret, sizeof(hash_bytes), out);
}

void hex256(hash_bytes &in, hash_str &out) {
const char *hex = "0123456789abcdef";
unsigned char *pin = in;
unsigned char *pout = out;
for (; pin < in + sizeof(in); pout += 2, pin++) {
pout[0] = hex[(*pin >> 4) & 0xF];
pout[1] = hex[*pin & 0xF];
}
}

} // namespace duckdb
5 changes: 5 additions & 0 deletions extension/httpfs/httpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,9 @@ void HTTPFileHandle::StoreClient(unique_ptr<HTTPClient> client) {
HTTPFileHandle::~HTTPFileHandle() {
DUCKDB_LOG_FILE_SYSTEM_CLOSE((*this));
};

string HTTPFSUtil::GetName() const {
return "HTTPFS";
}

} // namespace duckdb
16 changes: 16 additions & 0 deletions extension/httpfs/httpfs_client_wasm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "httpfs_client.hpp"
#include "http_state.hpp"

namespace duckdb {

unique_ptr<HTTPClient> HTTPFSUtil::InitializeClient(HTTPParams &http_params, const string &proto_host_port) {
throw InternalException("HTTPFSUtil::InitializeClient is not expected to be called");
}

unordered_map<string, string> HTTPFSUtil::ParseGetParameters(const string &text) {
unordered_map<string, string> result;
//TODO: HTTPFSUtil::ParseGetParameters is currently not implemented
return result;
}

} // namespace duckdb
Loading
Loading