Skip to content

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:

  • The scheme is https.
  • The authority is example.com.
  • The path is /foo/bar.
  • The query is baz=qux.

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:

src/uri/routes.rs
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.


  1. 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 access RequestHead::target without having to worry about it.