@@ -219,23 +219,17 @@ static std::string ConvertResultToXML(MaterializedQueryResult &result) {
219
219
void HandleHttpRequest (const duckdb_httplib_openssl::Request& req, duckdb_httplib_openssl::Response& res) {
220
220
std::string query;
221
221
222
- // Check authentication
223
- if (!IsAuthenticated (req)) {
224
- res.status = 401 ;
225
- res.set_content (" Unauthorized" , " text/plain" );
226
- return ;
227
- }
228
-
229
- // CORS allow
222
+ // CORS allow - set these headers for all requests
230
223
res.set_header (" Access-Control-Allow-Origin" , " *" );
231
224
res.set_header (" Access-Control-Allow-Methods" , " GET, POST, OPTIONS, PUT" );
232
- res.set_header (" Access-Control-Allow-Headers" , " * " );
225
+ res.set_header (" Access-Control-Allow-Headers" , " Content-Type, X-API-Key, Authorization, X-ClickHouse-Format, format " );
233
226
res.set_header (" Access-Control-Allow-Credentials" , " true" );
234
227
res.set_header (" Access-Control-Max-Age" , " 86400" );
235
228
236
- // Handle preflight OPTIONS request
237
- if (req.method == " OPTIONS" ) {
238
- res.status = 204 ; // No content
229
+ // Check authentication for actual requests (OPTIONS are handled separately)
230
+ if (!IsAuthenticated (req)) {
231
+ res.status = 401 ;
232
+ res.set_content (" Unauthorized" , " text/plain" );
239
233
return ;
240
234
}
241
235
@@ -344,15 +338,16 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
344
338
}
345
339
}
346
340
347
- // CORS Preflight
341
+ // CORS Preflight - no authentication required for OPTIONS requests
348
342
global_state.server ->Options (base_path,
349
343
[](const duckdb_httplib_openssl::Request& /* req*/ , duckdb_httplib_openssl::Response& res) {
350
344
res.set_header (" Access-Control-Allow-Methods" , " POST, GET, OPTIONS" );
351
345
res.set_header (" Content-Type" , " text/html; charset=utf-8" );
352
- res.set_header (" Access-Control-Allow-Headers" , " * " );
346
+ res.set_header (" Access-Control-Allow-Headers" , " Content-Type, X-API-Key, Authorization, X-ClickHouse-Format, format " );
353
347
res.set_header (" Access-Control-Allow-Origin" , " *" );
354
348
res.set_header (" Access-Control-Allow-Credentials" , " true" );
355
349
res.set_header (" Connection" , " close" );
350
+ res.status = 204 ; // No content for preflight
356
351
return duckdb_httplib_openssl::Server::HandlerResponse::Handled;
357
352
});
358
353
@@ -363,9 +358,13 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
363
358
global_state.server ->Get (base_path, HandleHttpRequest);
364
359
global_state.server ->Post (base_path, HandleHttpRequest);
365
360
366
- // Health check endpoint
367
- // Health check endpoint, now relative to base_path
361
+ // Health check endpoint - no authentication required
368
362
global_state.server ->Get (base_path + " ping" , [](const duckdb_httplib_openssl::Request& req, duckdb_httplib_openssl::Response& res) {
363
+ // Set CORS headers for health check endpoint
364
+ res.set_header (" Access-Control-Allow-Origin" , " *" );
365
+ res.set_header (" Access-Control-Allow-Methods" , " GET, OPTIONS" );
366
+ res.set_header (" Access-Control-Allow-Headers" , " Content-Type" );
367
+ res.set_header (" Access-Control-Allow-Credentials" , " true" );
369
368
res.set_content (" OK" , " text/plain" );
370
369
});
371
370
0 commit comments