@@ -122,6 +122,18 @@ std::shared_ptr<Aws::Http::HttpRequest> AWSInput::CreateSignedRequest(Aws::Http:
122
122
// return request;
123
123
}
124
124
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
+
125
137
unique_ptr<HTTPResponse> AWSInput::ExecuteRequest (ClientContext &context, Aws::Http::HttpMethod method,
126
138
const string body, string content_type) {
127
139
@@ -140,6 +152,11 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
140
152
// If access key is not set, we don't set the headers at all to allow accessing public files through s3 urls
141
153
142
154
string payload_hash = " e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ; // Empty payload hash
155
+
156
+ if (!body.empty ()) {
157
+ payload_hash = GetPayloadHash (body.c_str (), body.size ());
158
+ }
159
+
143
160
// key_id, secret, session_token
144
161
// we can pass date/time but this is mostly useful in testing. normally we just get the current datetime
145
162
// here.
@@ -161,6 +178,9 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
161
178
hash_str canonical_request_hash_str;
162
179
if (content_type.length () > 0 ) {
163
180
signed_headers += " content-type;" ;
181
+ #ifdef EMSCRIPTEN
182
+ res[" content-type" ] = content_type;
183
+ #endif
164
184
}
165
185
signed_headers += " host;x-amz-content-sha256;x-amz-date" ;
166
186
if (session_token.length () > 0 ) {
@@ -244,23 +264,14 @@ unique_ptr<HTTPResponse> AWSInput::ExecuteRequest(ClientContext &context, Aws::H
244
264
245
265
params = http_util.InitializeParameters (context, request_url);
246
266
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
-
260
267
if (method == Aws::Http::HttpMethod::HTTP_HEAD) {
261
268
HeadRequestInfo head_request (request_url, res, *params);
262
269
return http_util.Request (head_request);
263
270
}
271
+ if (method == Aws::Http::HttpMethod::HTTP_DELETE) {
272
+ DeleteRequestInfo delete_request (request_url, res, *params);
273
+ return http_util.Request (delete_request);
274
+ }
264
275
if (method == Aws::Http::HttpMethod::HTTP_GET) {
265
276
GetRequestInfo get_request (request_url, res, *params, nullptr , nullptr );
266
277
return http_util.Request (get_request);
0 commit comments