MCPcopy Create free account
hub / github.com/actix/examples / main

Function main

https-tls/awc-https/src/main.rs:39–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38#[actix_web::main]
39async fn main() -> std::io::Result<()> {
40 env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
41
42 let client_tls_config = Arc::new(rustls_config());
43
44 log::info!("Starting HTTP server at http://localhost:8080");
45
46 HttpServer::new(move || {
47 // create client _inside_ `HttpServer::new` closure to have one per worker thread
48 let client = Client::builder()
49 // Wikipedia requires a User-Agent header to make requests
50 .add_default_header((header::USER_AGENT, "awc-example/1.0"))
51 // a "connector" wraps the stream into an encrypted connection
52 .connector(Connector::new().rustls_0_23(Arc::clone(&client_tls_config)))
53 .finish();
54
55 App::new()
56 .app_data(ThinData(client))
57 .service(fetch_image)
58 .wrap(middleware::Logger::default())
59 })
60 .bind(("127.0.0.1", 8080))?
61 .workers(2)
62 .run()
63 .await
64}
65
66/// Create simple `rustls` client config.
67fn rustls_config() -> rustls::ClientConfig {

Callers

nothing calls this directly

Calls 2

rustls_configFunction · 0.85
runMethod · 0.80

Tested by

no test coverage detected