fix proxy response bug, add log for response object

This commit is contained in:
Jun Kurihara 2022-07-10 11:21:17 +09:00
commit 8a4149cbf2
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 50 additions and 7 deletions

View file

@ -0,0 +1,33 @@
use crate::{log::*, utils::*};
use hyper::Response;
use std::fmt::Display;
////////////////////////////////////////////////////
// Functions of utils for request messages
pub trait ResLog {
fn log<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
);
}
impl<B> ResLog for &Response<B> {
fn log<T1: Display, T2: Display + ToCanonical>(
self,
server_name: &T1,
client_addr: &T2,
extra: Option<&str>,
) {
let canonical_client_addr = client_addr.to_canonical();
info!(
"{} <- {} -- {} {:?} {:?} {}",
canonical_client_addr,
server_name,
self.status(),
self.version(),
self.headers(),
extra.map_or_else(|| "", |v| v)
);
}
}