Request target
All incoming HTTP requests include a target
in the request head.
The target is a URI1, either in absolute form (e.g. https://example.com/foo/bar?baz=qux
) or in
origin form (e.g. /foo/bar?baz=qux
).
URI components
A URI can be broken down into different components.
Let's take https://example.com/foo/bar?baz=qux
as an example:
If the request target is in origin form, the authority and the scheme are omitted: you're left with just the path and the query,
e.g. /foo/bar?baz=qux
.
Injection
Inject RequestHead
to access the request target via its target
field:
use pavex::http::StatusCode;
use pavex::request::RequestHead;
pub fn handler(head: &RequestHead) -> StatusCode {
println!("The request target is {}", head.target);
// [...]
}
Use cases
The raw target and its components are primarily useful for logging purposes.
Rely on higher-level abstractions
to perform more advanced processing—e.g. parsing query parameters or path parameters.
-
RFC 7230 allows two other formats of request target, authority form (e.g.
example.com:443
) and asterisk form (e.g.*
).
For both alternative formats there is a canonical conversion into a URI (effective request URI). Pavex takes care of the conversion automatically; you can accessRequestHead::target
without having to worry about it. ↩