pub struct Request {
pub method: Method,
pub uri: Uri,
pub version: Version,
pub headers: HeaderMap,
pub body: Bytes,
pub extensions: Extensions,
/* private fields */
}Expand description
Contains a incoming Http Request
Fields§
§method: MethodThe HTTP method of the request.
For example, GET, POST, PUT, DELETE, etc.
uri: UriThe URI of the request.
version: VersionThe HTTP version of the request.
headers: HeaderMapThe headers of the request.
body: BytesThe body of the request.
extensions: ExtensionsThe extensions of the request.
Implementations§
Source§impl Request
impl Request
Sourcepub fn parse(raw: &[u8]) -> Result<Request, Error>
pub fn parse(raw: &[u8]) -> Result<Request, Error>
Parses a Request from raw bytes if parsing fails returns a error
§Puts a None to as stream of the request!
Sourcepub fn take_stream(self) -> Option<TcpStream>
pub fn take_stream(self) -> Option<TcpStream>
Takes the stream of the request
This medhod takes ownership of the Request!
And also gives you to responsiblity give answer to the socket connection
This method is only intented to used by Power Users use it at your own risk.
§Usage:
Takes the stream out but you have to clone the request to do so.
if let Some(stream) = request.clone().take_stream(){
}The Reason of this is in the middlewares don’t allow you to have ownership of the request and response objects so to get ownership you have to clone it
Sourcepub fn has_stream(&self) -> bool
pub fn has_stream(&self) -> bool
Returns true if the Request has a Stream false if stream is taken
Sourcepub fn json(&self) -> Result<Value, Error>
pub fn json(&self) -> Result<Value, Error>
Parses the body of the request as Serde JSON Value. Returns an error if the body is not valid JSON.
This method is useful for parsing JSON payloads in requests.
Sourcepub fn query(&self) -> Result<HashMap<String, String>, Error>
pub fn query(&self) -> Result<HashMap<String, String>, Error>
Returns a Hashmap of the query parameters of the Request.
Returns a Error if parsing fails