mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 10:32:55 +01:00
417c06b00e
* fix: broken http stream when authentication failed Signed-off-by: Roland Ma <rolandma@outlook.com> * remove unchanged Signed-off-by: Roland Ma <rolandma@outlook.com> * Update CHANGES.md * Update CHANGES.md * Update CHANGES.md Co-authored-by: Rob Ede <robjtede@icloud.com>
27 lines
728 B
Rust
27 lines
728 B
Rust
use actix_web::dev::ServiceRequest;
|
|
use actix_web::{middleware, web, App, Error, HttpServer};
|
|
use actix_web_httpauth::extractors::basic::BasicAuth;
|
|
use actix_web_httpauth::middleware::HttpAuthentication;
|
|
|
|
async fn validator(
|
|
req: ServiceRequest,
|
|
_credentials: BasicAuth,
|
|
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
|
Ok(req)
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| {
|
|
let auth = HttpAuthentication::basic(validator);
|
|
App::new()
|
|
.wrap(middleware::Logger::default())
|
|
.wrap(auth)
|
|
.service(web::resource("/").to(|| async { "Test\r\n" }))
|
|
})
|
|
.bind("127.0.0.1:8080")?
|
|
.workers(1)
|
|
.run()
|
|
.await
|
|
}
|