mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
use remote addr in logger if available
This commit is contained in:
parent
f369d9af0e
commit
be3a1ab770
@ -9,6 +9,8 @@
|
||||
|
||||
* Content compression/decompression (br, gzip, deflate)
|
||||
|
||||
* Refactor logger middleware
|
||||
|
||||
|
||||
## 0.2.1 (2017-11-03)
|
||||
|
||||
|
@ -44,6 +44,7 @@ cookie = { version="0.10", features=["percent-encode", "secure"] }
|
||||
regex = "0.2"
|
||||
sha1 = "0.2"
|
||||
url = "1.5"
|
||||
libc = "^0.2"
|
||||
flate2 = "0.2"
|
||||
brotli2 = "^0.3.2"
|
||||
percent-encoding = "1.0"
|
||||
|
@ -173,7 +173,7 @@ impl<T, H> Http1<T, H>
|
||||
not_ready = false;
|
||||
|
||||
// set remote addr
|
||||
req.set_remove_addr(self.addr.clone());
|
||||
req.set_remove_addr(self.addr);
|
||||
|
||||
// stop keepalive timer
|
||||
self.keepalive_timer.take();
|
||||
|
@ -140,7 +140,7 @@ impl<T, H> Http2<T, H>
|
||||
self.keepalive_timer.take();
|
||||
|
||||
self.tasks.push_back(
|
||||
Entry::new(parts, body, resp, self.addr.clone(), &self.router));
|
||||
Entry::new(parts, body, resp, self.addr, &self.router));
|
||||
}
|
||||
Ok(Async::NotReady) => {
|
||||
// start keep-alive timer
|
||||
|
@ -75,11 +75,13 @@ impl HttpRequest {
|
||||
pub fn method(&self) -> &Method { &self.method }
|
||||
|
||||
/// Read the Request Version.
|
||||
#[inline]
|
||||
pub fn version(&self) -> Version {
|
||||
self.version
|
||||
}
|
||||
|
||||
/// Read the Request Headers.
|
||||
#[inline]
|
||||
pub fn headers(&self) -> &HeaderMap {
|
||||
&self.headers
|
||||
}
|
||||
@ -97,6 +99,7 @@ impl HttpRequest {
|
||||
/// - Forwarded
|
||||
/// - X-Forwarded-For
|
||||
/// - peername of opened socket
|
||||
#[inline]
|
||||
pub fn remote(&self) -> Option<&SocketAddr> {
|
||||
self.addr.as_ref()
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ extern crate http_range;
|
||||
extern crate mime;
|
||||
extern crate mime_guess;
|
||||
extern crate url;
|
||||
extern crate libc;
|
||||
extern crate flate2;
|
||||
extern crate brotli2;
|
||||
extern crate percent_encoding;
|
||||
|
@ -3,6 +3,7 @@ use std::env;
|
||||
use std::fmt;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use libc;
|
||||
use time;
|
||||
use regex::Regex;
|
||||
|
||||
@ -100,11 +101,18 @@ impl Logger {
|
||||
},
|
||||
FormatText::ResponseStatus => resp.status().as_u16().fmt(fmt),
|
||||
FormatText::ResponseSize => resp.response_size().fmt(fmt),
|
||||
FormatText::Pid => unsafe{libc::getpid().fmt(fmt)},
|
||||
FormatText::Time =>
|
||||
fmt.write_fmt(format_args!("{:.6}", response_time_ms/1000.0)),
|
||||
FormatText::TimeMillis =>
|
||||
fmt.write_fmt(format_args!("{:.6}", response_time_ms)),
|
||||
FormatText::RemoteAddr => Ok(()), //req.remote_addr.fmt(fmt),
|
||||
FormatText::RemoteAddr => {
|
||||
if let Some(addr) = req.remote() {
|
||||
addr.fmt(fmt)
|
||||
} else {
|
||||
"-".fmt(fmt)
|
||||
}
|
||||
}
|
||||
FormatText::RequestTime => {
|
||||
entry_time.strftime("[%d/%b/%Y:%H:%M:%S %z]")
|
||||
.unwrap()
|
||||
@ -205,7 +213,7 @@ impl Format {
|
||||
"%" => FormatText::Percent,
|
||||
"a" => FormatText::RemoteAddr,
|
||||
"t" => FormatText::RequestTime,
|
||||
"P" => FormatText::Percent,
|
||||
"P" => FormatText::Pid,
|
||||
"r" => FormatText::RequestLine,
|
||||
"s" => FormatText::ResponseStatus,
|
||||
"b" => FormatText::ResponseSize,
|
||||
@ -251,6 +259,7 @@ impl<'a> ContextDisplay<'a> for Format {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FormatText {
|
||||
Str(String),
|
||||
Pid,
|
||||
Percent,
|
||||
RequestLine,
|
||||
RequestTime,
|
||||
|
@ -279,9 +279,8 @@ impl Task {
|
||||
// finish middlewares
|
||||
if let Some(ref mut resp) = self.prepared {
|
||||
resp.set_response_size(io.written());
|
||||
match self.middlewares.finishing(req, resp) {
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
_ => (),
|
||||
if let Ok(Async::NotReady) = self.middlewares.finishing(req, resp) {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
}
|
||||
Ok(Async::Ready(self.state.is_done()))
|
||||
|
Loading…
Reference in New Issue
Block a user