Struct rust_xfinal::Request
source · 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
Examples found in repository?
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
pub fn new(name: String, req: &Request) -> Self {
let key = &*req.get_secret_key();
let path = req.url_to_path();
match req.get_header("Cookie") {
Some(s) => match cookie_str_to_map(s).get(name.as_str()) {
Some(&token) => {
match token.verify_with_key(key) {
Ok(x) => {
// let borrow:& mut BTreeMap<String, String> = & mut x;
return Cookie {
name,
path: String::from(path),
domain: String::new(),
max_age: None,
http_only: false,
data: x,
secret_key: req.get_secret_key(),
};
}
Err(_) => {}
}
}
None => {}
},
None => {}
}
Cookie {
name,
path: String::from(path),
domain: String::new(),
max_age: None,
http_only: false,
data: BTreeMap::new(),
secret_key: req.get_secret_key(),
}
}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)
Examples found in repository?
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
pub fn new(name: String, req: &Request) -> Self {
let key = &*req.get_secret_key();
let path = req.url_to_path();
match req.get_header("Cookie") {
Some(s) => match cookie_str_to_map(s).get(name.as_str()) {
Some(&token) => {
match token.verify_with_key(key) {
Ok(x) => {
// let borrow:& mut BTreeMap<String, String> = & mut x;
return Cookie {
name,
path: String::from(path),
domain: String::new(),
max_age: None,
http_only: false,
data: x,
secret_key: req.get_secret_key(),
};
}
Err(_) => {}
}
}
None => {}
},
None => {}
}
Cookie {
name,
path: String::from(path),
domain: String::new(),
max_age: None,
http_only: false,
data: BTreeMap::new(),
secret_key: req.get_secret_key(),
}
}