Skip to content

Commit 4a02d93

Browse files
committed
Implement DELETE and PUT with body
1 parent 0f4177b commit 4a02d93

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/aws.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ std::shared_ptr<Aws::Http::HttpRequest> AWSInput::CreateSignedRequest(Aws::Http:
122122
// return request;
123123
}
124124

125+
static string GetPayloadHash(const char *buffer, idx_t buffer_len) {
126+
if (buffer_len > 0) {
127+
hash_bytes payload_hash_bytes;
128+
hash_str payload_hash_str;
129+
sha256(buffer, buffer_len, payload_hash_bytes);
130+
hex256(payload_hash_bytes, payload_hash_str);
131+
return string((char *)payload_hash_str, sizeof(payload_hash_str));
132+
} else {
133+
return "";
134+
}
135+
}
136+
125137
unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::Http::HttpMethod method,
126138
const string body, string content_type) {
127139

@@ -140,6 +152,11 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
140152
// If access key is not set, we don't set the headers at all to allow accessing public files through s3 urls
141153

142154
string payload_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; // Empty payload hash
155+
156+
if (!body.empty()) {
157+
payload_hash = GetPayloadHash(body.c_str(), body.size());
158+
}
159+
143160
// key_id, secret, session_token
144161
// we can pass date/time but this is mostly useful in testing. normally we just get the current datetime
145162
// here.
@@ -161,6 +178,9 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
161178
hash_str canonical_request_hash_str;
162179
if (content_type.length() > 0) {
163180
signed_headers += "content-type;";
181+
#ifdef EMSCRIPTEN
182+
res["content-type"] = content_type;
183+
#endif
164184
}
165185
signed_headers += "host;x-amz-content-sha256;x-amz-date";
166186
if (session_token.length() > 0) {
@@ -244,23 +264,14 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
244264

245265
params = http_util.InitializeParameters(context, request_url);
246266

247-
if (!body.empty()) {
248-
throw NotImplementedException("CreateSignedRequest with non-empty body is not supported at this time");
249-
/*
250-
auto bodyStream = Aws::MakeShared<Aws::StringStream>("");
251-
*bodyStream << body;
252-
request->AddContentBody(bodyStream);
253-
request->SetContentLength(std::to_string(body.size()));
254-
if (!content_type.empty()) {
255-
request->SetHeaderValue("Content-Type", content_type);
256-
}
257-
*/
258-
}
259-
260267
if (method == Aws::Http::HttpMethod::HTTP_HEAD) {
261268
HeadRequestInfo head_request(request_url, res, *params);
262269
return http_util.Request(head_request);
263270
}
271+
if (method == Aws::Http::HttpMethod::HTTP_DELETE) {
272+
DeleteRequestInfo delete_request(request_url, res, *params);
273+
return http_util.Request(delete_request);
274+
}
264275
if (method == Aws::Http::HttpMethod::HTTP_GET) {
265276
GetRequestInfo get_request(request_url, res, *params, nullptr, nullptr);
266277
return http_util.Request(get_request);

0 commit comments

Comments
 (0)