feat: include uri on error page tracing log
resolves #108
--
the server now will show the requested uri when a file/dir is not found.
static-web-server -p 8787 -d docker/public/ -g warn
2022-05-08T20:39:57.864548Z WARN static_web_server::error_page: method=GET uri=/assets/abcdef?sort=1 status=404 error="Not Found"
2022-05-08T20:44:04.214944Z WARN static_web_server::error_page: method=GET uri=/assets/abc status=404 error="Not Found"
Diff
src/error_page.rs | 8 ++++++--
src/handler.rs | 6 ++++++
2 files changed, 12 insertions(+), 2 deletions(-)
@@ -1,17 +1,21 @@
use headers::{AcceptRanges, ContentLength, ContentType, HeaderMapExt};
use hyper::{Body, Method, Response, StatusCode};
use hyper::{Body, Method, Response, StatusCode, Uri};
use mime_guess::mime;
use crate::Result;
pub fn error_response(
uri: &Uri,
method: &Method,
status_code: &StatusCode,
page404: &[u8],
page50x: &[u8],
) -> Result<Response<Body>> {
tracing::warn!(method = ?method, status = status_code.as_u16(), error = ?status_code.to_owned());
tracing::warn!(
method = ?method, uri = ?uri, status = status_code.as_u16(),
error = status_code.canonical_reason().unwrap_or_default()
);
let mut error_page_content = String::new();
@@ -52,6 +52,7 @@ impl RequestHandler {
if !(method == Method::GET || method == Method::HEAD || method == Method::OPTIONS) {
return error_page::error_response(
uri,
method,
&StatusCode::METHOD_NOT_ALLOWED,
&self.opts.page404,
@@ -69,6 +70,7 @@ impl RequestHandler {
Err(err) => {
tracing::error!("cors error kind: {:?}", err);
return error_page::error_response(
uri,
method,
&StatusCode::FORBIDDEN,
&self.opts.page404,
@@ -84,6 +86,7 @@ impl RequestHandler {
if let Err(err) = basic_auth::check_request(headers, user_id, password) {
tracing::warn!("basic authentication failed {:?}", err);
let mut resp = error_page::error_response(
uri,
method,
&StatusCode::UNAUTHORIZED,
&self.opts.page404,
@@ -100,6 +103,7 @@ impl RequestHandler {
} else {
tracing::error!("invalid basic authentication `user_id:password` pairs");
return error_page::error_response(
uri,
method,
&StatusCode::INTERNAL_SERVER_ERROR,
&self.opts.page404,
@@ -138,6 +142,7 @@ impl RequestHandler {
Err(err) => {
tracing::error!("error during body compression: {:?}", err);
return error_page::error_response(
uri,
method,
&StatusCode::INTERNAL_SERVER_ERROR,
&self.opts.page404,
@@ -175,6 +180,7 @@ impl RequestHandler {
error_page::error_response(
uri,
method,
&status,
&self.opts.page404,