File: h2spec.rs

package info (click to toggle)
rust-actix-http 3.9.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::{convert::Infallible, io};

use actix_http::{HttpService, Request, Response, StatusCode};
use actix_server::Server;
use once_cell::sync::Lazy;

static STR: Lazy<String> = Lazy::new(|| "HELLO WORLD ".repeat(100));

#[actix_rt::main]
async fn main() -> io::Result<()> {
    env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

    Server::build()
        .bind("h2spec", ("127.0.0.1", 8080), || {
            HttpService::build()
                .h2(|_: Request| async move {
                    let mut res = Response::build(StatusCode::OK);
                    Ok::<_, Infallible>(res.body(&**STR))
                })
                .tcp()
        })?
        .workers(4)
        .run()
        .await
}