mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
add HttpRequest::uri_mut(), allows to modify request uri
This commit is contained in:
parent
d568161852
commit
7ad66956b2
@ -195,6 +195,15 @@ impl<S> HttpRequest<S> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn uri(&self) -> &Uri { &self.as_ref().uri }
|
pub fn uri(&self) -> &Uri { &self.as_ref().uri }
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[inline]
|
||||||
|
/// Modify the Request Uri.
|
||||||
|
///
|
||||||
|
/// This might be useful for middlewares, i.e. path normalization
|
||||||
|
pub fn uri_mut(&mut self) -> &mut Uri {
|
||||||
|
&mut self.as_mut().uri
|
||||||
|
}
|
||||||
|
|
||||||
/// Read the Request method.
|
/// Read the Request method.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn method(&self) -> &Method { &self.as_ref().method }
|
pub fn method(&self) -> &Method { &self.as_ref().method }
|
||||||
@ -768,7 +777,7 @@ impl Future for RequestBody {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use mime;
|
use mime;
|
||||||
use http::Uri;
|
use http::{Uri, HttpTryFrom};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use router::Pattern;
|
use router::Pattern;
|
||||||
use resource::Resource;
|
use resource::Resource;
|
||||||
@ -807,6 +816,14 @@ mod tests {
|
|||||||
assert_eq!(mt.subtype(), mime::JSON);
|
assert_eq!(mt.subtype(), mime::JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uri_mut() {
|
||||||
|
let mut req = HttpRequest::default();
|
||||||
|
assert_eq!(req.path(), "/");
|
||||||
|
*req.uri_mut() = Uri::try_from("/test").unwrap();
|
||||||
|
assert_eq!(req.path(), "/test");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_request_cookies() {
|
fn test_no_request_cookies() {
|
||||||
let req = HttpRequest::default();
|
let req = HttpRequest::default();
|
||||||
|
Loading…
Reference in New Issue
Block a user