mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +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]
|
||||
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.
|
||||
#[inline]
|
||||
pub fn method(&self) -> &Method { &self.as_ref().method }
|
||||
@ -768,7 +777,7 @@ impl Future for RequestBody {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use mime;
|
||||
use http::Uri;
|
||||
use http::{Uri, HttpTryFrom};
|
||||
use std::str::FromStr;
|
||||
use router::Pattern;
|
||||
use resource::Resource;
|
||||
@ -807,6 +816,14 @@ mod tests {
|
||||
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]
|
||||
fn test_no_request_cookies() {
|
||||
let req = HttpRequest::default();
|
||||
|
Loading…
Reference in New Issue
Block a user