1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-30 12:00:38 +00:00
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
Find a file
2018-09-11 09:05:47 -07:00
examples add generic server service factory 2018-09-08 14:50:16 -07:00
src fix openssl uses 2018-09-11 08:59:03 -07:00
.appveyor.yml cleanups 2018-08-21 21:11:16 -07:00
.gitignore initial import 2018-08-19 10:47:04 -07:00
.travis.yml move server impl to sub module 2018-09-11 08:43:23 -07:00
Cargo.toml refactor connections counter 2018-09-08 09:36:38 -07:00
CODE_OF_CONDUCT.md initial import 2018-08-19 10:47:04 -07:00
LICENSE-APACHE initial import 2018-08-19 10:47:04 -07:00
LICENSE-MIT initial import 2018-08-19 10:47:04 -07:00
README.md fix readme 2018-09-11 09:05:47 -07:00
rustfmt.toml initial import 2018-08-19 10:47:04 -07:00

Actix net Build Status codecov crates.io Join the chat at https://gitter.im/actix/actix

Actix net - framework for compossible network services

Documentation & community resources

Example

fn main() {
    let sys = actix::System::new("test");

    // load ssl keys
    let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
    builder.set_private_key_file("./examples/key.pem", SslFiletype::PEM).unwrap();
    builder.set_certificate_chain_file("./examples/cert.pem").unwrap();
    let acceptor = builder.build();

    let num = Arc::new(AtomicUsize::new(0));

    // bind socket address and start workers. By default server uses number of
    // available logical cpu as threads count. actix net start separate
    // instances of service pipeline in each worker.
    Server::default()
        .bind(
            // configure service pipeline
            "0.0.0.0:8443",
            move || {
                let num = num.clone();
                let acceptor = acceptor.clone();

                // service for converting incoming TcpStream to a SslStream<TcpStream>
                (move |stream| {
                SslAcceptorExt::accept_async(&acceptor, stream)
                    .map_err(|e| println!("Openssl error: {}", e))
            })
            // convert closure to a `NewService`
            .into_new_service()

            // .and_then() combinator uses other service to convert incoming `Request` to a `Response`
            // and then uses that response as an input for next service.
            // in this case, on success we use `logger` service
            .and_then(logger)

            // next service uses two components, service state and service function
            // actix-net generates `NewService` impl that creates `ServiceState` instance for each new service
            // and use `service` function as `Service::call`
            .and_then((service, move || {
                Ok(ServiceState { num: num.clone() })
            }))
            },
        ).unwrap()
        .start();

    sys.run();
}

License

This project is licensed under either of

at your option.

Code of Conduct

Contribution to the actix-net crate is organized under the terms of the Contributor Covenant, the maintainer of actix-net, @fafhrd91, promises to intervene to uphold that code of conduct.