You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use hyper::{header::HeaderValue,Body,Request,Response,Server};// Import the routerify prelude traits.use routerify::{Middleware,RequestInfo,Router,RouterService};use std::io;use std::net::SocketAddr;// A handler for "/" page.asyncfnhome_handler(_:Request<Body>) -> Result<Response<Body>, io::Error>{Ok(Response::new(Body::from("Home page")))}asyncfnpre(mutreq:Request<Body>) -> Result<Request<Body>, io::Error>{
req.headers_mut().insert("x-custom",HeaderValue::from_static("some value"));dbg!("pre", req.headers());Ok(req)}asyncfnpost(res:Response<Body>,req_info:RequestInfo) -> Result<Response<Body>, io::Error>{
req_info
.headers().get("x-custom").expect("should see header added in pre");Ok(res)}fnrouter() -> Router<Body, io::Error>{// Create a router and specify the the handlers.Router::builder().middleware(Middleware::pre(pre)).middleware(Middleware::post_with_info(post)).get("/", home_handler).build().unwrap()}#[tokio::main]asyncfnmain(){let router = router();// Create a Service from the router above to handle incoming requests.let service = RouterService::new(router).unwrap();// The address on which the server will be listening.let addr = SocketAddr::from(([127,0,0,1],3001));// Create a server by passing the created service to `.serve` method.let server = Server::bind(&addr).serve(service);println!("App is running on: {}", addr);ifletErr(err) = server.await{eprintln!("Server error: {}", err);}}
So it will panic with "should see header added in pre".
An example:
So it will panic with "should see header added in pre".
Is this an expected behavior?
Originally reported by @shanyp
The text was updated successfully, but these errors were encountered: