macro_rules! pub_request_impl { ($import:literal $($prefix:tt $suffix:tt)?) => { /// Retrieves the inner `Request` as seen by Rocket. /// /// # Example /// /// ```rust #[doc = $import] /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let inner: &rocket::Request = request.inner(); /// # }); /// ``` #[inline(always)] pub fn inner(&self) -> &Request<'c> { self._request() } /// Add a header to this request. /// /// Any type that implements `Into
` can be used here. Among /// others, this includes [`ContentType`] and [`Accept`]. /// /// [`ContentType`]: crate::http::ContentType /// [`Accept`]: crate::http::Accept /// /// # Examples /// /// Add the Content-Type header: /// /// ```rust #[doc = $import] /// use rocket::http::Header; /// use rocket::http::ContentType; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let req = request /// .header(ContentType::JSON) /// .header(Header::new("X-Custom", "custom-value")); /// # }); /// ``` #[inline] pub fn header(mut self, header: H) -> Self where H: Into> { self._request_mut().add_header(header.into()); self } /// Adds a header to this request without consuming `self`. /// /// # Examples /// /// Add the Content-Type header: /// /// ```rust #[doc = $import] /// use rocket::http::ContentType; /// /// # Client::_test(|_, mut request, _| { /// let mut request: LocalRequest = request; /// request.add_header(ContentType::JSON); /// # }); /// ``` #[inline] pub fn add_header(&mut self, header: H) where H: Into> { self._request_mut().add_header(header.into()); } /// Set the remote address of this request. /// /// # Examples /// /// Set the remote address to "8.8.8.8:80": /// /// ```rust #[doc = $import] /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let address = "8.8.8.8:80".parse().unwrap(); /// let req = request.remote(address); /// # }); /// ``` #[inline] pub fn remote(mut self, address: std::net::SocketAddr) -> Self { self._request_mut().set_remote(address); self } /// Add a cookie to this request. /// /// # Examples /// /// Add `user_id` cookie: /// /// ```rust #[doc = $import] /// use rocket::http::Cookie; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let req = request /// .cookie(Cookie::new("username", "sb")) /// .cookie(Cookie::new("user_id", "12")); /// # }); /// ``` #[inline] pub fn cookie(mut self, cookie: crate::http::Cookie<'_>) -> Self { self._request_mut().cookies_mut().add_original(cookie.into_owned()); self } /// Add all of the cookies in `cookies` to this request. /// /// # Example /// /// ```rust #[doc = $import] /// use rocket::http::Cookie; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let cookies = vec![Cookie::new("a", "b"), Cookie::new("c", "d")]; /// let req = request.cookies(cookies); /// # }); /// ``` #[inline] pub fn cookies<'a, C>(mut self, cookies: C) -> Self where C: IntoIterator> { for cookie in cookies { self._request_mut().cookies_mut().add_original(cookie.into_owned()); } self } /// Add a [private cookie] to this request. /// /// [private cookie]: crate::http::CookieJar::add_private() /// /// # Examples /// /// Add `user_id` as a private cookie: /// /// ```rust #[doc = $import] /// use rocket::http::Cookie; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let req = request.private_cookie(Cookie::new("user_id", "sb")); /// # }); /// ``` #[cfg(feature = "secrets")] #[cfg_attr(nightly, doc(cfg(feature = "secrets")))] #[inline] pub fn private_cookie(mut self, cookie: crate::http::Cookie<'static>) -> Self { self._request_mut().cookies_mut().add_original_private(cookie); self } /// Set the body (data) of the request. /// /// # Examples /// /// Set the body to be a JSON structure; also sets the Content-Type. /// /// ```rust #[doc = $import] /// use rocket::http::ContentType; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let req = request /// .header(ContentType::JSON) /// .body(r#"{ "key": "value", "array": [1, 2, 3] }"#); /// # }); /// ``` #[inline] pub fn body>(mut self, body: S) -> Self { // TODO: For CGI, we want to be able to set the body to be stdin // without actually reading everything into a vector. Can we allow // that here while keeping the simplicity? Looks like it would // require us to reintroduce a NetStream::Local(Box) or // something like that. *self._body_mut() = body.as_ref().into(); self } /// Set the body (data) of the request without consuming `self`. /// /// # Examples /// /// Set the body to be a JSON structure; also sets the Content-Type. /// /// ```rust #[doc = $import] /// use rocket::http::ContentType; /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let mut request = request.header(ContentType::JSON); /// request.set_body(r#"{ "key": "value", "array": [1, 2, 3] }"#); /// # }); /// ``` #[inline] pub fn set_body>(&mut self, body: S) { *self._body_mut() = body.as_ref().into(); } /// Dispatches the request, returning the response. /// /// This method consumes `self` and is the preferred mechanism for /// dispatching. /// /// # Example /// /// ```rust #[doc = $import] /// /// # Client::_test(|_, request, _| { /// let request: LocalRequest = request; /// let response = request.dispatch(); /// # }); /// ``` #[inline(always)] pub $($prefix)? fn dispatch(self) -> LocalResponse<'c> { self._dispatch()$(.$suffix)? } #[cfg(test)] #[allow(dead_code)] fn _ensure_impls_exist() { fn is_clone_debug() {} is_clone_debug::(); } }}