Skip to content
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

Throw HTTP error for status != 200 in InitializeMultipartUpload #10

Merged
merged 4 commits into from
Feb 4, 2025
Merged
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
10 changes: 8 additions & 2 deletions extension/httpfs/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,19 @@ string S3FileSystem::InitializeMultipartUpload(S3FileHandle &file_handle) {
string query_param = "uploads=";
auto res = s3fs.PostRequest(file_handle, file_handle.path, {}, response_buffer, response_buffer_len, nullptr, 0,
query_param);

if (res->code != 200) {
throw HTTPException(*res, "Unable to connect to URL %s: %s (HTTP code %s)", res->http_url, res->error,
to_string(res->code));
}

string result(response_buffer.get(), response_buffer_len);

auto open_tag_pos = result.find("<UploadId>", 0);
auto close_tag_pos = result.find("</UploadId>", open_tag_pos);

if (open_tag_pos == string::npos || close_tag_pos == string::npos) {
throw std::runtime_error("Unexpected response while initializing S3 multipart upload");
throw HTTPException("Unexpected response while initializing S3 multipart upload");
}

open_tag_pos += 10; // Skip open tag
Expand Down Expand Up @@ -315,7 +321,7 @@ void S3FileSystem::UploadBuffer(S3FileHandle &file_handle, shared_ptr<S3WriteBuf
query_param);

if (res->code != 200) {
throw HTTPException(*res, "Unable to connect to URL %s %s (HTTP code %s)", res->http_url, res->error,
throw HTTPException(*res, "Unable to connect to URL %s: %s (HTTP code %s)", res->http_url, res->error,
to_string(res->code));
}

Expand Down
Loading