use std::cell::{Ref, RefCell, RefMut}; use std::{fmt, mem}; use bytes::Bytes; use futures::Stream; use http::{header, HeaderMap, Method, Uri, Version}; use crate::error::PayloadError; use crate::extensions::Extensions; use crate::httpmessage::HttpMessage; use crate::message::{Message, RequestHead}; use crate::payload::{Payload, PayloadStream}; /// Request pub struct Request
{
pub(crate) payload: RefCell HttpMessage for Request
where
P: Stream From {
fn from(msg: Message Request {
/// Create new Request instance
pub fn with_payload(payload: Payload ) -> Request {
Request {
payload: RefCell::new(payload),
inner: Message::new(),
}
}
/// Create new Request instance
pub fn set_payload(self, payload: I) -> Request ) {
(self.inner, self.payload.into_inner())
}
#[inline]
/// Http message part of the request
pub fn head(&self) -> &RequestHead {
&*self.inner
}
#[inline]
#[doc(hidden)]
/// Mutable reference to a http message part of the request
pub fn head_mut(&mut self) -> &mut RequestHead {
&mut *self.inner
}
/// Request's uri.
#[inline]
pub fn uri(&self) -> &Uri {
&self.head().uri
}
/// Mutable reference to the request's uri.
#[inline]
pub fn uri_mut(&mut self) -> &mut Uri {
&mut self.head_mut().uri
}
/// Read the Request method.
#[inline]
pub fn method(&self) -> &Method {
&self.head().method
}
/// Read the Request Version.
#[inline]
pub fn version(&self) -> Version {
self.head().version
}
/// The target path of this Request.
#[inline]
pub fn path(&self) -> &str {
self.head().uri.path()
}
#[inline]
/// Returns Request's headers.
pub fn headers(&self) -> &HeaderMap {
&self.head().headers
}
#[inline]
/// Returns mutable Request's headers.
pub fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.head_mut().headers
}
/// Request extensions
#[inline]
pub fn extensions(&self) -> Ref