use rs_express::{App, NextFunction, Request, Response}; use hyper::{http::StatusCode, Body, Client}; #[tokio::test] async fn test_sanity() { let mut app: App<()> = App::new(); app.use_ok( |req: &mut Request<()>, res: &mut Response, next: &mut NextFunction| { let header_value = req.header("x-custom-header").unwrap(); res.set_header("x-custom-header", header_value.as_str()); next(Ok(())); }, ) .use_ok( |_: &mut Request<()>, res: &mut Response, _next: &mut NextFunction| { res.set_header("x-custom-header2", "hello"); res.end(); }, ); tokio::spawn(async move { app.listen(3000).await.expect("Failed to listen"); }); let client = Client::new(); let request = hyper::Request::builder() .header("x-custom-header", "rs_express") .uri("http://localhost:3000") .body(Body::from("body")) .expect("Request builder failed"); let response = client .request(request) .await .expect("Failed on get request"); assert_eq!(response.status(), StatusCode::OK); assert_eq!( response .headers() .get("x-custom-header") .expect("x-custom-header header value") .to_str() .unwrap(), "rs_express" ); assert_eq!( response .headers() .get("x-custom-header2") .expect("x-custom-header2 header value") .to_str() .unwrap(), "hello" ); }