@@ -501,10 +501,11 @@ namespace HttpServer
501501 rawPairsToStlMap (outgoing_headers, response.headers , response.headers_count );
502502 }
503503
504- if (response. headers_count && response. headers )
504+ try
505505 {
506- destroyRawPairs (response.headers , response.headers_count );
506+ app_sets-> application_clear (response.headers , response.headers_count );
507507 }
508+ catch (...) {}
508509
509510 destroyRawPairs (raw_pair_params, incoming_params.size () );
510511 destroyRawPairs (raw_pair_headers, incoming_headers.size () );
@@ -930,71 +931,77 @@ namespace HttpServer
930931
931932 if (app_call)
932933 {
933- std::function<bool ()> app_init = std::function<bool ()>();
934-
935- if (module .find (" application_init" , &addr) )
936- {
937- app_init = reinterpret_cast <bool (*)()>(addr);
938- }
939-
940- std::function<void ()> app_final = std::function<void ()>();
941-
942- if (module .find (" application_final" , &addr) )
934+ if (module .find (" application_clear" , &addr) )
943935 {
944- app_final = reinterpret_cast <void (*)()>(addr);
945- }
936+ std::function<void (Utils::raw_pair [], const size_t )> app_clear = reinterpret_cast <void (*)(Utils::raw_pair [], const size_t )>(addr);
946937
947- bool success = true ;
938+ std::function< bool ()> app_init = std::function< bool ()>() ;
948939
949- try
950- {
951- if (app_init)
940+ if (module .find (" application_init" , &addr) )
952941 {
953- success = app_init ( );
942+ app_init = reinterpret_cast < bool (*)()>(addr );
954943 }
955- }
956- catch (...)
957- {
958- success = false ;
959- }
960-
961- if (success)
962- {
963- auto it_temp_dir = app.find (" temp_dir" );
964-
965- const std::string temp_dir = app.end () != it_temp_dir ? it_temp_dir->second : default_temp_dir;
966-
967- auto it_request_max_size = app.find (" request_max_size" );
968944
969- const size_t request_max_size = app. end () != it_request_max_size ? std::stoull (it_request_max_size-> second ) : default_request_max_size ;
945+ std::function< void ()> app_final = std::function< void ()>() ;
970946
971- // Если путь к директории заканчивается слешем, то убираем его
972- if (' /' == it_root_dir->second .back () )
947+ if (module .find (" application_final" , &addr) )
973948 {
974- it_root_dir-> second . assign (it_root_dir-> second . cbegin (), it_root_dir-> second . cend () - 1 );
949+ app_final = reinterpret_cast < void (*)()>(addr );
975950 }
976951
977- ServerApplicationSettings *sets = new ServerApplicationSettings {
978- it_root_dir->second ,
979- temp_dir,
980- request_max_size,
981- app_call,
982- app_init,
983- app_final
984- };
952+ bool success = true ;
985953
986- if (names. empty () )
954+ try
987955 {
988- apps_tree.addApplication (app_name, sets);
956+ if (app_init)
957+ {
958+ success = app_init ();
959+ }
960+ }
961+ catch (...)
962+ {
963+ success = false ;
989964 }
990- else
965+
966+ if (success)
991967 {
992- for (size_t i = 0 ; i < names.size (); ++i)
968+ auto it_temp_dir = app.find (" temp_dir" );
969+
970+ const std::string temp_dir = app.end () != it_temp_dir ? it_temp_dir->second : default_temp_dir;
971+
972+ auto it_request_max_size = app.find (" request_max_size" );
973+
974+ const size_t request_max_size = app.end () != it_request_max_size ? std::stoull (it_request_max_size->second ) : default_request_max_size;
975+
976+ // Если путь к директории заканчивается слешем, то убираем его
977+ if (' /' == it_root_dir->second .back () )
993978 {
994- apps_tree. addApplication (names[i], sets );
979+ it_root_dir-> second . pop_back ( );
995980 }
996- }
997- } // end success
981+
982+ ServerApplicationSettings *sets = new ServerApplicationSettings {
983+ it_root_dir->second ,
984+ temp_dir,
985+ request_max_size,
986+ app_call,
987+ app_clear,
988+ app_init,
989+ app_final
990+ };
991+
992+ if (names.empty () )
993+ {
994+ apps_tree.addApplication (app_name, sets);
995+ }
996+ else
997+ {
998+ for (size_t i = 0 ; i < names.size (); ++i)
999+ {
1000+ apps_tree.addApplication (names[i], sets);
1001+ }
1002+ }
1003+ } // end success
1004+ } // end if module find
9981005 } // end if app_call
9991006 } // end module find
10001007 } // end module.is_open()
0 commit comments