fn spawn_http_server(
    gs: Arc<GlobalState>,
    acceptor: ssl::SslAcceptorBuilder,
) -> Result<dev::Server, PortBindError> {
    // obtain config options
    let server_info = format!(
        "{name} v{version} ({spec}) - {url}",
        name = c::PROG_NAME,
        version = c::VERSION,
        spec = c::SPEC,
        url = c::REPO_URL
    );
    let ad_headers = !gs.config.disable_ad_headers;
    let bind_addr = format!("{}:{}", &gs.config.bind_address, gs.config.port);
    let data = web::Data::new(Arc::clone(&gs));

    // initialize server object
    let mut server = HttpServer::new(move || {
        let mut default_headers = middleware::DefaultHeaders::new()
            // Headers required by client spec
            .header("X-Content-Type-Options", "nosniff")
            .header("Access-Control-Allow-Origin", "*")
            .header("Access-Control-Expose-Headers", "*")
            .header("Access-Control-Expose-Methods", "GET")
            .header("Cache-Control", "public, max-age=1209600")
            .header("Timing-Allow-Origin", "*");
        // include Advertisement headers if enabled in configuration
        if ad_headers {
            default_headers = default_headers
                .header("Server", &server_info)
                .header("X-Powered-By", "Actix Web")
                .header("X-Version", c::VERSION)
        }

        App::new()
            .app_data(data.clone())
            .wrap(default_headers)
            .wrap(
                middleware::Logger::new("(%a) \"%r\" (status = %s, size = %bb) in %Dms")
                    .exclude("/prometheus"),
            )
            // regular MD@Home routes
            .route(
                "/{token}/{archive_type}/{chap_hash}/{image}", // tokenized route
                web::get().to(md_service),
            )
            .route(
                "/{archive_type}/{chap_hash}/{image}", // untokenized route
                web::get().to(md_service),
            )
            // Prom metrics route
            .route("/prometheus", web::get().to(prom_service))
            .default_service(web::route().to(not_found_service))
    })
    .keep_alive(gs.config.keep_alive)
    .shutdown_timeout(60)
    .disable_signals();

    // manually set worker thread count to config amount
    if let Some(worker_threads) = gs.config.worker_threads {
        server = server.workers(worker_threads);
    }

    if gs.config.disable_ssl {
        server.bind(&bind_addr)
    } else {
        server.bind_openssl(&bind_addr, acceptor)
    }
    .map_err(PortBindError)
    .map(|s| s.run())
}
/// Spawns an Actix HTTP server in this thread with the Ssl Acceptor provided
///
/// This will bind to the port provided in the configuration using OpenSSL.
Spawns an Actix HTTP server in this thread with the Ssl Acceptor provided
This will bind to the port provided in the configuration using OpenSSL.
Spawns an Actix HTTP server in this thread with the Ssl Acceptor provided This will bind to the port provided in the configuration using OpenSSL .
fn spawn_http_server(
    gs: Arc<GlobalState>,
    acceptor: ssl::SslAcceptorBuilder,
) -> Result<dev::Server, PortBindError> {
    // obtain config options
    let server_info = format!(
        "{name} v{version} ({spec}) - {url}",
        name = c::PROG_NAME,
        version = c::VERSION,
        spec = c::SPEC,
        url = c::REPO_URL
    );
    let ad_headers = !gs.config.disable_ad_headers;
    let bind_addr = format!("{}:{}", &gs.config.bind_address, gs.config.port);
    let data = web::Data::new(Arc::clone(&gs));
    // initialize server object
    let mut server = HttpServer::new(move || {
        let mut default_headers = middleware::DefaultHeaders::new()
            // Headers required by client spec
            .header("X-Content-Type-Options", "nosniff")
            .header("Access-Control-Allow-Origin", "*")
            .header("Access-Control-Expose-Headers", "*")
            .header("Access-Control-Expose-Methods", "GET")
            .header("Cache-Control", "public, max-age=1209600")
            .header("Timing-Allow-Origin", "*");
        // include Advertisement headers if enabled in configuration
        if ad_headers {
            default_headers = default_headers
                .header("Server", &server_info)
                .header("X-Powered-By", "Actix Web")
                .header("X-Version", c::VERSION)
        }
        App::new()
            .app_data(data.clone())
            .wrap(default_headers)
            .wrap(
                middleware::Logger::new("(%a) \"%r\" (status = %s, size = %bb) in %Dms")
                    .exclude("/prometheus"),
            )
            // regular MD@Home routes
            .route(
                "/{token}/{archive_type}/{chap_hash}/{image}", // tokenized route
                web::get().to(md_service),
            )
            .route(
                "/{archive_type}/{chap_hash}/{image}", // untokenized route
                web::get().to(md_service),
            )
            // Prom metrics route
            .route("/prometheus", web::get().to(prom_service))
            .default_service(web::route().to(not_found_service))
    })
    .keep_alive(gs.config.keep_alive)
    .shutdown_timeout(60)
    .disable_signals();
    // manually set worker thread count to config amount
    if let Some(worker_threads) = gs.config.worker_threads {
        server = server.workers(worker_threads);
    }
    if gs.config.disable_ssl {
        server.bind(&bind_addr)
    } else {
        server.bind_openssl(&bind_addr, acceptor)
    }
    .map_err(PortBindError)
    .map(|s| s.run())
}
fn spawn_http_server ( gs : Arc < GlobalState > , acceptor : ssl :: SslAcceptorBuilder , ) -> Result < dev :: Server , PortBindError > { // obtain config options let server_info = format ! ( " " name c PROG_NAME version c VERSION spec c SPEC url c REPO_URL ) ; let ad_headers = ! gs . config . disable_ad_headers ; let bind_addr = format ! ( " " gs config bind_address gs config port ) ; let data = web :: Data :: new ( Arc :: clone ( & gs ) ) ; // initialize server object let mut server = HttpServer :: new ( move | | { let mut default_headers = middleware :: DefaultHeaders :: new ( ) // Headers required by client spec . header ( " " , " " ) . header ( " " , " " ) . header ( " " , " " ) . header ( " " , " " ) . header ( " " , " " ) . header ( " " , " " ) ; // include Advertisement headers if enabled in configuration if ad_headers { default_headers = default_headers . header ( " " , & server_info ) . header ( " " , " " ) . header ( " " , c :: VERSION ) } App :: new ( ) . app_data ( data . clone ( ) ) . wrap ( default_headers ) . wrap ( middleware :: Logger :: new ( " \" \" " ) . exclude ( " " ) , ) // regular MD@Home routes . route ( " " , // tokenized route web :: get ( ) . to ( md_service ) , ) . route ( " " , // untokenized route web :: get ( ) . to ( md_service ) , ) // Prom metrics route . route ( " " , web :: get ( ) . to ( prom_service ) ) . default_service ( web :: route ( ) . to ( not_found_service ) ) } ) . keep_alive ( gs . config . keep_alive ) . shutdown_timeout ( 60 ) . disable_signals ( ) ; // manually set worker thread count to config amount if let Some ( worker_threads ) = gs . config . worker_threads { server = server . workers ( worker_threads ) ; } if gs . config . disable_ssl { server . bind ( & bind_addr ) } else { server . bind_openssl ( & bind_addr , acceptor ) } . map_err ( PortBindError ) . map ( | s | s . run ( ) ) }
Spawns an Actix HTTP server in this thread with the Ssl Acceptor provided
This will bind to the port provided in the configuration using OpenSSL.
Spawns an Actix HTTP server in this thread with the Ssl Acceptor provided This will bind to the port provided in the configuration using OpenSSL .
gs
Arc<GlobalState>
acceptor
ssl::SslAcceptorBuilder