Requested Updates (Route => URLPath, %R => %U)

This commit is contained in:
haze 2019-04-03 17:29:38 -04:00
parent 56d0f6607b
commit 127f1b0bce
2 changed files with 9 additions and 7 deletions

View File

@ -6,6 +6,8 @@
* Renamed `TestRequest::to_response()` to `TestRequest::to_srv_response()` * Renamed `TestRequest::to_response()` to `TestRequest::to_srv_response()`
* Added `URLPath` option for logger
### Removed ### Removed

View File

@ -65,7 +65,7 @@ use crate::{HttpMessage, HttpResponse};
/// ///
/// `%D` Time taken to serve the request, in milliseconds /// `%D` Time taken to serve the request, in milliseconds
/// ///
/// `%R` Request route /// `%U` Request URL
/// ///
/// `%{FOO}i` request.headers['FOO'] /// `%{FOO}i` request.headers['FOO']
/// ///
@ -274,7 +274,7 @@ impl Format {
/// Returns `None` if the format string syntax is incorrect. /// Returns `None` if the format string syntax is incorrect.
pub fn new(s: &str) -> Format { pub fn new(s: &str) -> Format {
log::trace!("Access log format: {}", s); log::trace!("Access log format: {}", s);
let fmt = Regex::new(r"%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrRsbTD]?)").unwrap(); let fmt = Regex::new(r"%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrUsbTD]?)").unwrap();
let mut idx = 0; let mut idx = 0;
let mut results = Vec::new(); let mut results = Vec::new();
@ -302,7 +302,7 @@ impl Format {
"r" => FormatText::RequestLine, "r" => FormatText::RequestLine,
"s" => FormatText::ResponseStatus, "s" => FormatText::ResponseStatus,
"b" => FormatText::ResponseSize, "b" => FormatText::ResponseSize,
"R" => FormatText::Route, "U" => FormatText::UrlPath,
"T" => FormatText::Time, "T" => FormatText::Time,
"D" => FormatText::TimeMillis, "D" => FormatText::TimeMillis,
_ => FormatText::Str(m.as_str().to_owned()), _ => FormatText::Str(m.as_str().to_owned()),
@ -331,7 +331,7 @@ pub enum FormatText {
Time, Time,
TimeMillis, TimeMillis,
RemoteAddr, RemoteAddr,
Route, UrlPath,
RequestHeader(String), RequestHeader(String),
ResponseHeader(String), ResponseHeader(String),
EnvironHeader(String), EnvironHeader(String),
@ -417,7 +417,7 @@ impl FormatText {
)) ))
}; };
} }
FormatText::Route => { FormatText::UrlPath => {
*self = FormatText::Str(format!( *self = FormatText::Str(format!(
"{}", "{}",
req.path() req.path()
@ -484,8 +484,8 @@ mod tests {
} }
#[test] #[test]
fn test_route() { fn test_url_path() {
let mut format = Format::new("%T %R"); let mut format = Format::new("%T %U");
let req = TestRequest::with_header( let req = TestRequest::with_header(
header::USER_AGENT, header::USER_AGENT,
header::HeaderValue::from_static("ACTIX-WEB"), header::HeaderValue::from_static("ACTIX-WEB"),