diff options
author | Bao Trinh <qubidt@gmail.com> | 2023-07-26 00:03:17 +0000 |
---|---|---|
committer | Bao Trinh <qubidt@gmail.com> | 2023-07-26 00:52:24 +0000 |
commit | 6ef212cb326c91edd315f5a797a90de3796e980b (patch) | |
tree | 3bf3e0e9249c529c4ab34499501f72dd893b2a93 | |
parent | Consolidate javascript and add comments (diff) | |
download | miniserve-6ef212cb326c91edd315f5a797a90de3796e980b.tar.gz miniserve-6ef212cb326c91edd315f5a797a90de3796e980b.zip |
Fix error page wrapping
Error page was incorrectly comparing the full content-type header of
error responses against `text/plain`, so no error pages were being
wrapped by `map_error_page`.
-rw-r--r-- | src/errors.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/errors.rs b/src/errors.rs index e502634..6875b90 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -5,6 +5,7 @@ use actix_web::{ HttpRequest, HttpResponse, ResponseError, }; use futures::prelude::*; +use std::str::FromStr; use thiserror::Error; use crate::{renderer::render_error, MiniserveConfig}; @@ -131,8 +132,15 @@ where let res = fut.await?.map_into_boxed_body(); if (res.status().is_client_error() || res.status().is_server_error()) - && res.headers().get(header::CONTENT_TYPE).map(AsRef::as_ref) - == Some(mime::TEXT_PLAIN_UTF_8.essence_str().as_bytes()) + && res + .headers() + .get(header::CONTENT_TYPE) + .map(AsRef::as_ref) + .and_then(|s| std::str::from_utf8(s).ok()) + .and_then(|s| mime::Mime::from_str(s).ok()) + .as_ref() + .map(mime::Mime::essence_str) + == Some(mime::TEXT_PLAIN.as_ref()) { let req = res.request().clone(); Ok(res.map_body(|head, body| map_error_page(&req, head, body))) |