diff options
author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2021-08-28 21:40:32 +0000 |
---|---|---|
committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2021-08-28 21:40:32 +0000 |
commit | f8bf27d5b761c071e158158b3c140d59a75b8eb8 (patch) | |
tree | c9da0a390923673ccb007488a35cb5baaa4ffca2 /src/main.rs | |
parent | Add CHANGELOG entry for backslash encoding contribution (diff) | |
download | miniserve-f8bf27d5b761c071e158158b3c140d59a75b8eb8.tar.gz miniserve-f8bf27d5b761c071e158158b3c140d59a75b8eb8.zip |
migrate to actix-web v4.0-beta
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index c60e153..036d796 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ use actix_web::{ Responder, }; use actix_web::{middleware, App, HttpRequest, HttpResponse}; -use actix_web_httpauth::middleware::HttpAuthentication; use anyhow::Result; use log::{error, warn}; use structopt::clap::crate_version; @@ -213,10 +212,11 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { App::new() .wrap(configure_header(&inside_config.clone())) .app_data(inside_config.clone()) - .wrap(middleware::Condition::new( - !inside_config.auth.is_empty(), - HttpAuthentication::basic(auth::handle_auth), - )) + // we should use `actix_web_httpauth::middleware::HttpAuthentication` + // but it is unfortuantrly broken + // see: https://github.com/actix/actix-extras/issues/127 + // TODO replace this when fixed upstream + .wrap_fn(auth::auth_middleware) .wrap(middleware::Logger::default()) .route( &format!("/{}", inside_config.favicon_route), @@ -345,6 +345,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { ) }) .prefer_utf8(true) + .redirect_to_slash_directory() .default_handler(web::to(error_404)); Some(files) } @@ -417,14 +418,14 @@ async fn error_404(req: HttpRequest) -> HttpResponse { async fn favicon() -> impl Responder { let logo = include_str!("../data/logo.svg"); - web::HttpResponse::Ok() - .set(ContentType(mime::IMAGE_SVG)) + HttpResponse::Ok() + .insert_header(ContentType(mime::IMAGE_SVG)) .message_body(logo.into()) } async fn css() -> impl Responder { let css = include_str!(concat!(env!("OUT_DIR"), "/style.css")); - web::HttpResponse::Ok() - .set(ContentType(mime::TEXT_CSS)) + HttpResponse::Ok() + .insert_header(ContentType(mime::TEXT_CSS)) .message_body(css.into()) } |