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
67 changes: 25 additions & 42 deletions src/httpfs_curl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,13 @@ class HTTPFSCurlClient : public HTTPClient {
}

unique_ptr<HTTPResponse> Get(GetRequestInfo &info) override {
ResetRequestInfo();
if (state) {
state->get_count++;
}

auto curl_headers = TransformHeadersCurl(info.headers);
auto curl_headers = TransformHeadersCurl(info.headers, info.params);
request_info->url = info.url;
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}

CURLcode res;
{
Expand All @@ -226,6 +223,13 @@ class HTTPFSCurlClient : public HTTPClient {
state->total_bytes_received += bytes_received;
}

if (info.response_handler) {
auto response = TransformResponseCurl(res);
if (!info.response_handler(*response)) {
return response;
}
}

Comment on lines +226 to +232
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you possibly check the similar code in httpfs_httplib_client.cpp:

        unique_ptr<HTTPResponse> Get(GetRequestInfo &info) override {
                if (state) {
                        state->get_count++;
                }
                auto headers = TransformHeaders(info.headers, info.params);
                if (!info.response_handler && !info.content_handler) {
                        return TransformResult(client->Get(info.path, headers));
                } else {
                        return TransformResult(client->Get(
                            info.path.c_str(), headers,
                            [&](const duckdb_httplib_openssl::Response &response) {
                                    auto http_response = TransformResponse(response);
                                    return info.response_handler(*http_response);
                            },
                            [&](const char *data, size_t data_length) {
                                    if (state) {
                                            state->total_bytes_received += data_length;
                                    }
                                    return info.content_handler(const_data_ptr_cast(data), data_length);
                            }));
                }
        }

In particular, I am not sure if they can be made more similar to each other the GET handling.

const char *data = request_info->body.c_str();
if (info.content_handler) {
info.content_handler(const_data_ptr_cast(data), bytes_received);
Expand All @@ -235,20 +239,17 @@ class HTTPFSCurlClient : public HTTPClient {
}

unique_ptr<HTTPResponse> Put(PutRequestInfo &info) override {
ResetRequestInfo();
if (state) {
state->put_count++;
state->total_bytes_sent += info.buffer_in_len;
}

auto curl_headers = TransformHeadersCurl(info.headers);
auto curl_headers = TransformHeadersCurl(info.headers, info.params);
// Add content type header from info
curl_headers.Add("Content-Type: " + info.content_type);
// transform parameters
request_info->url = info.url;
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}

CURLcode res;
{
Expand All @@ -272,17 +273,14 @@ class HTTPFSCurlClient : public HTTPClient {
}

unique_ptr<HTTPResponse> Head(HeadRequestInfo &info) override {
ResetRequestInfo();
if (state) {
state->head_count++;
}

auto curl_headers = TransformHeadersCurl(info.headers);
auto curl_headers = TransformHeadersCurl(info.headers, info.params);
request_info->url = info.url;
// transform parameters
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}

CURLcode res;
{
Expand All @@ -306,17 +304,14 @@ class HTTPFSCurlClient : public HTTPClient {
}

unique_ptr<HTTPResponse> Delete(DeleteRequestInfo &info) override {
ResetRequestInfo();
if (state) {
state->delete_count++;
}

auto curl_headers = TransformHeadersCurl(info.headers);
auto curl_headers = TransformHeadersCurl(info.headers, info.params);
// transform parameters
request_info->url = info.url;
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}

CURLcode res;
{
Expand All @@ -343,20 +338,17 @@ class HTTPFSCurlClient : public HTTPClient {
}

unique_ptr<HTTPResponse> Post(PostRequestInfo &info) override {
ResetRequestInfo();
if (state) {
state->post_count++;
state->total_bytes_sent += info.buffer_in_len;
}

auto curl_headers = TransformHeadersCurl(info.headers);
auto curl_headers = TransformHeadersCurl(info.headers, info.params);
const string content_type = "Content-Type: application/octet-stream";
curl_headers.Add(content_type.c_str());
// transform parameters
request_info->url = info.url;
if (!info.params.extra_headers.empty()) {
auto curl_params = TransformParamsCurl(info.params);
request_info->url += "?" + curl_params;
}

CURLcode res;
{
Expand All @@ -382,7 +374,9 @@ class HTTPFSCurlClient : public HTTPClient {
}

private:
CURLRequestHeaders TransformHeadersCurl(const HTTPHeaders &header_map) {
CURLRequestHeaders TransformHeadersCurl(const HTTPHeaders &header_map, const HTTPParams &params) {
auto &httpfs_params = params.Cast<HTTPFSParams>();

std::vector<std::string> headers;
for (auto &entry : header_map) {
const std::string new_header = entry.first + ": " + entry.second;
Expand All @@ -392,23 +386,12 @@ class HTTPFSCurlClient : public HTTPClient {
for (auto &header : headers) {
curl_headers.Add(header);
}
return curl_headers;
}

string TransformParamsCurl(const HTTPParams &params) {
string result = "";
unordered_map<string, string> escaped_params;
bool first_param = true;
for (auto &entry : params.extra_headers) {
const string key = entry.first;
const string value = curl_easy_escape(*curl, entry.second.c_str(), 0);
if (!first_param) {
result += "&";
if (!httpfs_params.pre_merged_headers) {
for (auto &entry : params.extra_headers) {
curl_headers.Add(entry.first + ": " + entry.second);
}
result += key + "=" + value;
first_param = false;
}
return result;
return curl_headers;
}

void ResetRequestInfo() {
Expand Down Expand Up @@ -441,7 +424,7 @@ class HTTPFSCurlClient : public HTTPClient {
response->headers.Insert(header.first, header.second);
}
}
ResetRequestInfo();
// ResetRequestInfo();
return response;
}

Expand Down
3 changes: 1 addition & 2 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,13 +1236,12 @@ string AWSListObjectV2::Request(string &path, HTTPParams &http_params, S3AuthPar
req_params += "&delimiter=%2F";
}

string listobjectv2_url = req_path + "?" + req_params;

auto header_map =
CreateS3Header(req_path, req_params, parsed_url.host, "s3", "GET", s3_auth_params, "", "", "", "");

// Get requests use fresh connection
string full_host = parsed_url.http_proto + parsed_url.host;
string listobjectv2_url = full_host + req_path + "?" + req_params;
std::stringstream response;
GetRequestInfo get_request(
full_host, listobjectv2_url, header_map, http_params,
Expand Down
Loading