| 99 | |
| 100 | template < typename Server_Traits > |
| 101 | void run_server( const app_args_t & args ) |
| 102 | { |
| 103 | // Since RESTinio supports both stand-alone ASIO and boost::ASIO |
| 104 | // we specify an alias for a concrete asio namesace. |
| 105 | // That's makes it possible to compile the code in both cases. |
| 106 | // Typicaly only one of ASIO variants would be used, |
| 107 | // and so only asio::* or only boost::asio::* would be applied. |
| 108 | namespace asio_ns = restinio::asio_ns; |
| 109 | |
| 110 | asio_ns::ssl::context tls_context{ asio_ns::ssl::context::sslv23 }; |
| 111 | tls_context.set_options( |
| 112 | asio_ns::ssl::context::default_workarounds |
| 113 | | asio_ns::ssl::context::no_sslv2 |
| 114 | | asio_ns::ssl::context::single_dh_use ); |
| 115 | |
| 116 | tls_context.use_certificate_chain_file( args.m_certs_dir + "/server.pem" ); |
| 117 | tls_context.use_private_key_file( |
| 118 | args.m_certs_dir + "/key.pem", |
| 119 | asio_ns::ssl::context::pem ); |
| 120 | tls_context.use_tmp_dh_file( args.m_certs_dir + "/dh2048.pem" ); |
| 121 | |
| 122 | restinio::run( |
| 123 | restinio::on_thread_pool< Server_Traits >( args.m_pool_size ) |
| 124 | .port( args.m_port ) |
| 125 | .address( args.m_address ) |
| 126 | .concurrent_accepts_count( args.m_pool_size ) |
| 127 | .tls_context( std::move( tls_context ) ) |
| 128 | .request_handler( |
| 129 | [&]( auto req ){ |
| 130 | if( restinio::http_method_get() == req->header().method() && |
| 131 | req->header().request_target() == "/" ) |
| 132 | { |
| 133 | try |
| 134 | { |
| 135 | auto sf = restinio::sendfile( args.m_file ); |
| 136 | sf.offset_and_size( |
| 137 | args.m_data_offset, |
| 138 | args.m_data_size ); |
| 139 | |
| 140 | return |
| 141 | req->create_response() |
| 142 | .append_header( |
| 143 | restinio::http_field::server, |
| 144 | "RESTinio hello world server" ) |
| 145 | .append_header_date_field() |
| 146 | .append_header( |
| 147 | restinio::http_field::content_type, |
| 148 | args.m_content_type ) |
| 149 | .set_body( std::move( sf ) ) |
| 150 | .done(); |
| 151 | } |
| 152 | catch( const std::exception & ) |
| 153 | { |
| 154 | return req->create_response( restinio::status_not_found() ) |
| 155 | .connection_close() |
| 156 | .append_header_date_field() |
| 157 | .done(); |
| 158 | } |
nothing calls this directly
no test coverage detected