pub struct RequestId { /* private fields */ }Expand description
A request’s reference: shown on error pages and carried by every event, so a visitor’s report finds the log line.
It displays as 16 hexadecimal digits, a keyed hash of the connection id
and the request’s number with a key made at start-up: the same request
always shows the same reference in one process, and two references say
nothing about how much traffic came between them (the raw counters
would). connection and seq give the
raw values for the logs. Not a security token.
use web_net::{App, get};
let app = App::builder().route(get("/", |cx| cx.text(200, &cx.id().to_string()))).build()?;
let r = serve_net::testing::respond(&app, b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
assert_eq!(r.text().len(), 16);Implementations§
Source§impl RequestId
impl RequestId
Sourcepub const fn connection(&self) -> u64
pub const fn connection(&self) -> u64
The connection id.
use web_net::{App, get};
let app = App::builder()
.route(get("/", |cx| {
let connection = cx.id().connection().to_string();
cx.text(200, &connection)
}))
.build()?;
let r = serve_net::testing::respond(&app, b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
assert!(r.text().parse::<u64>().is_ok());Sourcepub const fn seq(&self) -> u32
pub const fn seq(&self) -> u32
The request’s number on its connection.
use web_net::{App, get};
let app = App::builder()
.route(get("/", |cx| {
let seq = cx.id().seq().to_string();
cx.text(200, &seq)
}))
.build()?;
let r = serve_net::testing::respond(&app, b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
assert_eq!(r.text(), "1"); // the first request on its connectionTrait Implementations§
impl Copy for RequestId
impl Eq for RequestId
impl StructuralPartialEq for RequestId
Auto Trait Implementations§
impl Forget for RequestId
impl Freeze for RequestId
impl Move for RequestId
impl RefUnwindSafe for RequestId
impl Send for RequestId
impl Sync for RequestId
impl Unpin for RequestId
impl UnsafeUnpin for RequestId
impl UnwindSafe for RequestId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more