Struct submillisecond::RequestContext
source · pub struct RequestContext {
pub request: Request<Body<'static>>,
pub params: Params,
pub reader: UriReader,
/* private fields */
}
Expand description
Wrapper for http::Request
containing params and cursor.
Fields§
§request: Request<Body<'static>>
The http::Request
instance.
params: Params
Params collected from the router.
reader: UriReader
The uri reader.
Implementations§
source§impl RequestContext
impl RequestContext
sourcepub fn new(request: Request<Body<'static>>, stream: TcpStream) -> Self
pub fn new(request: Request<Body<'static>>, stream: TcpStream) -> Self
Creates a new instance of request context.
sourcepub fn next_handler(self) -> Response
pub fn next_handler(self) -> Response
Call the next handler, returning the response.
Panics
This function might panic if no next handler exists.
sourcepub fn set_next_handler(&mut self, next: fn(_: RequestContext) -> Response)
pub fn set_next_handler(&mut self, next: fn(_: RequestContext) -> Response)
Set the next handler.
This is used internally by the router!
macro.
Methods from Deref<Target = Request<Body<'static>>>§
sourcepub fn method(&self) -> &Method
pub fn method(&self) -> &Method
Returns a reference to the associated HTTP method.
Examples
let request: Request<()> = Request::default();
assert_eq!(*request.method(), Method::GET);
sourcepub fn method_mut(&mut self) -> &mut Method
pub fn method_mut(&mut self) -> &mut Method
Returns a mutable reference to the associated HTTP method.
Examples
let mut request: Request<()> = Request::default();
*request.method_mut() = Method::PUT;
assert_eq!(*request.method(), Method::PUT);
sourcepub fn uri(&self) -> &Uri
pub fn uri(&self) -> &Uri
Returns a reference to the associated URI.
Examples
let request: Request<()> = Request::default();
assert_eq!(*request.uri(), *"/");
sourcepub fn uri_mut(&mut self) -> &mut Uri
pub fn uri_mut(&mut self) -> &mut Uri
Returns a mutable reference to the associated URI.
Examples
let mut request: Request<()> = Request::default();
*request.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*request.uri(), *"/hello");
sourcepub fn version(&self) -> Version
pub fn version(&self) -> Version
Returns the associated version.
Examples
let request: Request<()> = Request::default();
assert_eq!(request.version(), Version::HTTP_11);
sourcepub fn version_mut(&mut self) -> &mut Version
pub fn version_mut(&mut self) -> &mut Version
Returns a mutable reference to the associated version.
Examples
let mut request: Request<()> = Request::default();
*request.version_mut() = Version::HTTP_2;
assert_eq!(request.version(), Version::HTTP_2);
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Returns a reference to the associated header field map.
Examples
let request: Request<()> = Request::default();
assert!(request.headers().is_empty());
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
Returns a mutable reference to the associated header field map.
Examples
let mut request: Request<()> = Request::default();
request.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!request.headers().is_empty());
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
Examples
let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());
sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a mutable reference to the associated extensions.
Examples
let mut request: Request<()> = Request::default();
request.extensions_mut().insert("hello");
assert_eq!(request.extensions().get(), Some(&"hello"));