Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote_addr() from RequestExt to RequestInfo #113

Open
brandonros opened this issue May 12, 2022 · 1 comment
Open

Add remote_addr() from RequestExt to RequestInfo #113

brandonros opened this issue May 12, 2022 · 1 comment

Comments

@brandonros
Copy link

async fn pre_router_logger(req: Request<Body>) -> Result<Request<Body>, Infallible> {
  req.set_context(RequestContext {
    start: Instant::now()
  });
  info!("pre: {} {} {}", req.remote_addr(), req.method(), req.uri().path());
  Ok(req)
}

async fn post_router_logger(res: Response<Body>, req_info: RequestInfo) -> Result<Response<Body>, Infallible> {
  let request_context = req_info.context::<RequestContext>().unwrap();
  let elapsed = request_context.start.elapsed().as_millis();
  info!("post: {}ms {} {} {}", elapsed, req_info.remote_addr(), req_info.method(), req_info.uri().path());
  Ok(res)
}

Would make something like this possible?

@brandonros
Copy link
Author

error[E0599]: no method named `remote_addr` found for struct `RequestInfo` in the current scope
    --> src/diag.rs:1193:50
     |
1193 |   info!("post: {}ms {} {} {}", elapsed, req_info.remote_addr(), req_info.method(), req_info.uri().path());
     |                                                  ^^^^^^^^^^^ method not found in `RequestInfo`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant