1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

add HttpRequest::uri_mut(), allows to modify request uri

This commit is contained in:
Nikolay Kim 2018-02-03 08:31:32 -08:00
parent d568161852
commit 7ad66956b2

View File

@ -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();