@@ -579,7 +579,8 @@ class Server {
579579 Server &Options (const char *pattern, Handler handler);
580580
581581 bool set_base_dir (const char *dir, const char *mount_point = nullptr );
582- bool set_mount_point (const char *mount_point, const char *dir);
582+ bool set_mount_point (const char *mount_point, const char *dir,
583+ Headers headers = Headers());
583584 bool remove_mount_point (const char *mount_point);
584585 void set_file_extension_and_mimetype_mapping (const char *ext,
585586 const char *mime);
@@ -663,9 +664,15 @@ class Server {
663664 ContentReceiver multipart_receiver);
664665
665666 virtual bool process_and_close_socket (socket_t sock);
667+
668+ struct MountPointEntry {
669+ std::string mount_point;
670+ std::string base_dir;
671+ Headers headers;
672+ };
673+ std::vector<MountPointEntry> base_dirs_;
666674
667675 std::atomic<bool > is_running_;
668- std::vector<std::pair<std::string, std::string>> base_dirs_;
669676 std::map<std::string, std::string> file_extension_and_mimetype_map_;
670677 Handler file_request_handler_;
671678 Handlers get_handlers_;
@@ -3815,11 +3822,12 @@ inline bool Server::set_base_dir(const char *dir, const char *mount_point) {
38153822 return set_mount_point (mount_point, dir);
38163823}
38173824
3818- inline bool Server::set_mount_point (const char *mount_point, const char *dir) {
3825+ inline bool Server::set_mount_point (const char *mount_point, const char *dir,
3826+ Headers headers) {
38193827 if (detail::is_dir (dir)) {
38203828 std::string mnt = mount_point ? mount_point : " /" ;
38213829 if (!mnt.empty () && mnt[0 ] == ' /' ) {
3822- base_dirs_.emplace_back ( mnt, dir);
3830+ base_dirs_.push_back ({ mnt, dir, std::move (headers)} );
38233831 return true ;
38243832 }
38253833 }
@@ -3828,7 +3836,7 @@ inline bool Server::set_mount_point(const char *mount_point, const char *dir) {
38283836
38293837inline bool Server::remove_mount_point (const char *mount_point) {
38303838 for (auto it = base_dirs_.begin (); it != base_dirs_.end (); ++it) {
3831- if (it->first == mount_point) {
3839+ if (it->mount_point == mount_point) {
38323840 base_dirs_.erase (it);
38333841 return true ;
38343842 }
@@ -4250,22 +4258,22 @@ inline bool Server::read_content_core(Stream &strm, Request &req, Response &res,
42504258
42514259inline bool Server::handle_file_request (Request &req, Response &res,
42524260 bool head) {
4253- for (const auto &kv : base_dirs_) {
4254- const auto &mount_point = kv.first ;
4255- const auto &base_dir = kv.second ;
4256-
4261+ for (const auto &entry : base_dirs_) {
42574262 // Prefix match
4258- if (!req.path .compare (0 , mount_point.size (), mount_point)) {
4259- std::string sub_path = " /" + req.path .substr (mount_point.size ());
4263+ if (!req.path .compare (0 , entry. mount_point .size (), entry. mount_point )) {
4264+ std::string sub_path = " /" + req.path .substr (entry. mount_point .size ());
42604265 if (detail::is_valid_path (sub_path)) {
4261- auto path = base_dir + sub_path;
4266+ auto path = entry. base_dir + sub_path;
42624267 if (path.back () == ' /' ) { path += " index.html" ; }
42634268
42644269 if (detail::is_file (path)) {
42654270 detail::read_file (path, res.body );
42664271 auto type =
42674272 detail::find_content_type (path, file_extension_and_mimetype_map_);
42684273 if (type) { res.set_header (" Content-Type" , type); }
4274+ for (const auto & kv : entry.headers ) {
4275+ res.set_header (kv.first .c_str (), kv.second );
4276+ }
42694277 res.status = 200 ;
42704278 if (!head && file_request_handler_) {
42714279 file_request_handler_ (req, res);
0 commit comments