rocket/local/blocking/
request.rsuse std::fmt;
use crate::{Request, http::Method, local::asynchronous};
use crate::http::uri::Origin;
use super::{Client, LocalResponse};
#[derive(Clone)]
pub struct LocalRequest<'c> {
inner: asynchronous::LocalRequest<'c>,
client: &'c Client,
}
impl<'c> LocalRequest<'c> {
#[inline]
pub(crate) fn new<'u: 'c, U>(client: &'c Client, method: Method, uri: U) -> Self
where U: TryInto<Origin<'u>> + fmt::Display
{
let inner = asynchronous::LocalRequest::new(client.inner(), method, uri);
Self { inner, client }
}
#[inline]
fn _request(&self) -> &Request<'c> {
self.inner._request()
}
#[inline]
fn _request_mut(&mut self) -> &mut Request<'c> {
self.inner._request_mut()
}
fn _body_mut(&mut self) -> &mut Vec<u8> {
self.inner._body_mut()
}
fn _dispatch(self) -> LocalResponse<'c> {
let inner = self.client.block_on(self.inner.dispatch());
LocalResponse { inner, client: self.client }
}
pub_request_impl!("# use rocket::local::blocking::Client;\n\
use rocket::local::blocking::LocalRequest;");
}
impl std::fmt::Debug for LocalRequest<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self._request().fmt(f)
}
}
impl<'c> std::ops::Deref for LocalRequest<'c> {
type Target = Request<'c>;
fn deref(&self) -> &Self::Target {
self.inner()
}
}
impl<'c> std::ops::DerefMut for LocalRequest<'c> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner_mut()
}
}