Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Apr 21, 2020
1 parent c0178f8 commit d19bb31
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use ::oauth2::State;
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use futures::prelude::*;
use hyper::{body::Body, error, header, server, service, Method, Request, Response, StatusCode};
use hyper::{
body::Body,
error, header,
server::{conn::AddrStream, Server},
service, Method, Request, Response, StatusCode,
};
use parking_lot::Mutex;
use relative_path::RelativePathBuf;
use serde::{de, Deserialize, Serialize};
Expand Down Expand Up @@ -49,11 +54,13 @@ pub fn setup(
let addr: SocketAddr = str::parse(&bind)?;

// TODO: add graceful shutdown.
let server_future = server::Server::bind(&addr).serve(service::make_service_fn(move |_| {
let handler = handler.clone();
let service = service::service_fn(move |req| handler.clone().call(req));
async move { Ok::<_, hyper::Error>(service) }
}));
let server_future =
Server::bind(&addr).serve(service::make_service_fn(move |s: &AddrStream| {
let handler = handler.clone();
let address = s.remote_addr();
let service = service::service_fn(move |req| handler.clone().call(address, req));
async move { Ok::<_, hyper::Error>(service) }
}));

let future = async move {
let mut interval = tokio::time::interval(time::Duration::from_secs(30)).fuse();
Expand Down Expand Up @@ -247,6 +254,7 @@ impl Handler {

async fn call(
self: Arc<Self>,
remote_address: SocketAddr,
mut req: Request<Body>,
) -> Result<Response<Body>, anyhow::Error> {
let path = req
Expand Down Expand Up @@ -346,7 +354,8 @@ impl Handler {

log::info!(
target: "request",
"{method} {uri} (User Agent: {user_agent}) ({request_len} bytes) => {status} ({response_len} bytes)",
"{remote_address} {method} {uri} (User Agent: {user_agent}) ({request_len} bytes) => {status} ({response_len} bytes)",
remote_address = remote_address,
method = req.method(),
uri = req.uri(),
user_agent = user_agent,
Expand Down

0 comments on commit d19bb31

Please sign in to comment.