@@ -261,6 +261,46 @@ static void HTTPPostRequestFunction(DataChunk &args, ExpressionState &state, Vec
261
261
});
262
262
}
263
263
264
+ static void HTTPPostFormRequestFunction (DataChunk &args, ExpressionState &state, Vector &result) {
265
+ D_ASSERT (args.data .size () == 3 );
266
+
267
+ using STRING_TYPE = PrimitiveType<string_t >;
268
+ using LENTRY_TYPE = PrimitiveType<list_entry_t >;
269
+
270
+ auto &url_vector = args.data [0 ];
271
+ auto &headers_vector = args.data [1 ];
272
+ auto &headers_entry = ListVector::GetEntry (headers_vector);
273
+ auto &body_vector = args.data [2 ];
274
+ auto &body_entry = ListVector::GetEntry (body_vector);
275
+
276
+ GenericExecutor::ExecuteTernary<STRING_TYPE, LENTRY_TYPE, LENTRY_TYPE, STRING_TYPE>(
277
+ url_vector, headers_vector, body_vector, result, args.size (),
278
+ [&](STRING_TYPE url, LENTRY_TYPE headers, LENTRY_TYPE params) {
279
+ std::string url_str = url.val .GetString ();
280
+
281
+ // Use helper to setup client and parse URL
282
+ auto client_and_path = SetupHttpClient (url_str);
283
+ auto &client = client_and_path.first ;
284
+ auto &path = client_and_path.second ;
285
+
286
+ // Prepare headers and parameters
287
+ duckdb_httplib_openssl::Headers header_map;
288
+ duckdb_httplib_openssl::Params params_map;
289
+ ConvertListEntryToMap<duckdb_httplib_openssl::Headers>(headers.val , headers_entry, header_map);
290
+ ConvertListEntryToMap<duckdb_httplib_openssl::Params>(params.val , body_entry, params_map);
291
+
292
+ // Make the POST request with headers and params
293
+ auto res = client.Post (path.c_str (), header_map, params_map);
294
+ if (res) {
295
+ std::string response = GetJsonResponse (res->status , res->reason , res->body );
296
+ return StringVector::AddString (result, response);
297
+ } else {
298
+ std::string response = GetJsonResponse (-1 , GetHttpErrorMessage (res, " POST" ), " " );
299
+ return StringVector::AddString (result, response);
300
+ }
301
+ });
302
+ }
303
+
264
304
265
305
static void LoadInternal (DatabaseInstance &instance) {
266
306
ScalarFunctionSet http_get (" http_get" );
@@ -276,6 +316,13 @@ static void LoadInternal(DatabaseInstance &instance) {
276
316
{LogicalType::VARCHAR, LogicalType::MAP (LogicalType::VARCHAR, LogicalType::VARCHAR), LogicalType::JSON ()},
277
317
LogicalType::JSON (), HTTPPostRequestFunction));
278
318
ExtensionUtil::RegisterFunction (instance, http_post);
319
+
320
+ ScalarFunctionSet http_post_form (" http_post_form" );
321
+ http_post_form.AddFunction (ScalarFunction (
322
+ {LogicalType::VARCHAR, LogicalType::MAP (LogicalType::VARCHAR, LogicalType::VARCHAR),
323
+ LogicalType::MAP (LogicalType::VARCHAR, LogicalType::VARCHAR)},
324
+ LogicalType::JSON (), HTTPPostFormRequestFunction));
325
+ ExtensionUtil::RegisterFunction (instance, http_post_form);
279
326
}
280
327
281
328
void HttpClientExtension::Load (DuckDB &db) {
0 commit comments