|
15 | 15 | #include <csignal> |
16 | 16 | #include <atomic> |
17 | 17 | #include <thread> |
| 18 | + |
18 | 19 | namespace fs = std::filesystem; |
19 | 20 |
|
20 | 21 | namespace { |
21 | 22 | // Global server pointer for signal handling |
22 | 23 | std::atomic<httplib::Server*> g_server_ptr{nullptr}; |
23 | | - unsigned int n = std::thread::hardware_concurrency(); |
24 | 24 |
|
25 | 25 | // Configuration |
26 | 26 | struct Config { |
27 | 27 | bool show_hidden = false; |
28 | 28 | size_t page_size = 100; |
29 | | - int thread_pool_size = n; |
| 29 | + int thread_pool_size = 1; |
30 | 30 | bool follow_symlinks = false; |
31 | 31 | } g_config; |
32 | 32 |
|
@@ -202,7 +202,7 @@ namespace { |
202 | 202 | return html.str(); |
203 | 203 | } |
204 | 204 |
|
205 | | - // Parse query parameters |
| 205 | + // Parse query parameters |
206 | 206 | std::unordered_map<std::string, std::string> parse_query(const std::string& query) { |
207 | 207 | std::unordered_map<std::string, std::string> params; |
208 | 208 | if (query.empty()) return params; |
@@ -449,7 +449,13 @@ namespace { |
449 | 449 | } |
450 | 450 | } |
451 | 451 |
|
452 | | -int start_server(const std::string& root_path, int port) { |
| 452 | +// Updated signature to accept page_size and thread_pool_size |
| 453 | +int start_server(const std::string& root_path, int port, size_t page_size, int thread_pool_size) { |
| 454 | + // Update global config |
| 455 | + g_config.page_size = page_size; |
| 456 | + // Ensure at least 1 thread |
| 457 | + g_config.thread_pool_size = (thread_pool_size > 0) ? thread_pool_size : 1; |
| 458 | + |
453 | 459 | httplib::Server svr; |
454 | 460 |
|
455 | 461 | // Setup signal handlers for graceful shutdown |
@@ -572,11 +578,11 @@ int start_server(const std::string& root_path, int port) { |
572 | 578 | return; |
573 | 579 | } |
574 | 580 |
|
575 | | - auto query_params = parse_query(req.get_header_value("Query-String")); |
576 | | - // Also parse from URL if httplib doesn't provide it |
577 | | - size_t query_pos = req.path.find('?'); |
578 | | - if (query_pos != std::string::npos) { |
579 | | - query_params = parse_query(req.path.substr(query_pos + 1)); |
| 581 | + // FIX: httplib parses query strings into req.params automatically. |
| 582 | + // We use req.params instead of manually parsing req.path. |
| 583 | + std::unordered_map<std::string, std::string> query_params; |
| 584 | + for (const auto& param : req.params) { |
| 585 | + query_params[param.first] = param.second; |
580 | 586 | } |
581 | 587 |
|
582 | 588 | serve_directory(p, url_path, query_params, res); |
|
0 commit comments