pub struct Request<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Request<'a>
impl<'a> Request<'a>
Sourcepub fn get_header(&self, key: &str) -> Option<&str>
pub fn get_header(&self, key: &str) -> Option<&str>
Get the value of a header pair by specifying the key
For example, Content-length: 123
get_header(“Content-length”), the key is not case senstive
Sourcepub fn get_param(&self, k: &str) -> Option<&str>
pub fn get_param(&self, k: &str) -> Option<&str>
Get the value of a parameter in the requested url
§For example
/path?id=1
get_param("id")
returns 1, the key is case senstive
Sourcepub fn get_params(&self) -> Option<HashMap<&str, &str>>
pub fn get_params(&self) -> Option<HashMap<&str, &str>>
Get the HashMap of the parameters in the requested url
§For example
/path?id=1&flag=true
get_params()
returns{id:1, flag:true }
Sourcepub fn get_headers(&self) -> HashMap<&str, &str>
pub fn get_headers(&self) -> HashMap<&str, &str>
Get the complete http headers
{"Content-length":"1", "key":"value",...}
Sourcepub fn get_version(&self) -> &str
pub fn get_version(&self) -> &str
Get the version of http request
Sourcepub fn get_query(&self, k: &str) -> Option<&str>
pub fn get_query(&self, k: &str) -> Option<&str>
Query the value of www-form-urlencoded or the text part of the multipart-form
- The key is not case senstive
§For example
Assume the form has the value
id=1
, then get_query(“id”) returns Some(“1”)
Sourcepub fn get_file(&self, k: &str) -> Option<&MultipleFormFile>
pub fn get_file(&self, k: &str) -> Option<&MultipleFormFile>
This method is used to acquire the file in the multipart-form data
§For example,
<form>
<input type="file" name="file1" />
</form>
get_file("file1")
return the file’s meta data
Sourcepub fn get_queries(&self) -> Option<HashMap<&str, &str>>
pub fn get_queries(&self) -> Option<HashMap<&str, &str>>
Return a HashMap that comprises all pairs in the www-form-urlencoded or the text part of the multipart-form
- It is safety called even though the request is
GET
, which returns None
Sourcepub fn get_files(&self) -> Option<Vec<&MultipleFormFile>>
pub fn get_files(&self) -> Option<Vec<&MultipleFormFile>>
Returns an array comprises of all files in the multipart-form data
Sourcepub fn plain_body(&self) -> Option<&str>
pub fn plain_body(&self) -> Option<&str>
Returns the body of a request
- it is used for getting the posted JSON or other plain text body
Sourcepub fn get_conn(&self) -> Rc<RefCell<&'a mut TcpStream>>
pub fn get_conn(&self) -> Rc<RefCell<&'a mut TcpStream>>
Return the raw instance of TcpStream
- This method should be carefully used, It is better to only get some meta information of a connection, such as a peer IP
Sourcepub fn get_method(&self) -> &str
pub fn get_method(&self) -> &str
Return the requested http method
Sourcepub fn url_to_path(&self) -> &str
pub fn url_to_path(&self) -> &str
Return the part of url exclude the parameters(if any)