aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs20
2 files changed, 13 insertions, 9 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0851f9d..ef325df 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,5 +16,5 @@ maintenance = { status = "actively-developed" }
[dependencies]
clap = "2.29"
actix = "0.5"
-actix-web = { git = "https://github.com/svenstaro/actix-web.git" }
+actix-web = { git = "https://github.com/actix/actix-web.git" }
simplelog = "0.5"
diff --git a/src/main.rs b/src/main.rs
index a83b6f6..2258fac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,7 +6,7 @@ extern crate simplelog;
extern crate clap;
use actix_web::http::{StatusCode, header};
-use actix_web::{server, App, fs, middleware, HttpRequest, HttpResponse, Result};
+use actix_web::{server, App, fs, middleware, HttpRequest, HttpResponse, HttpMessage, Result};
use actix_web::middleware::{Middleware, Response};
use simplelog::{TermLogger, LevelFilter, Config};
use std::path::PathBuf;
@@ -37,6 +37,10 @@ fn is_valid_interface(interface: String) -> Result<(), String> {
interface.parse::<IpAddr>().and(Ok(())).or_else(|e| Err(e.to_string()))
}
+fn is_valid_auth(auth: String) -> Result<(), String> {
+ auth.find(':').ok_or("Auth is not in form user:password".to_owned()).map(|_| ())
+}
+
pub fn parse_args() -> MiniserveConfig {
use clap::{App, Arg};
@@ -80,7 +84,8 @@ pub fn parse_args() -> MiniserveConfig {
Arg::with_name("auth")
.short("a")
.long("auth")
- .help("Set a password")
+ .validator(is_valid_auth)
+ .help("Set authentication (user:password)")
.takes_value(true),
)
.get_matches();
@@ -124,13 +129,12 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> {
struct Auth;
-impl<S> Middleware<S> for Auth {
- fn response(&self, req: &mut HttpRequest<S>, mut resp: HttpResponse) -> Result<Response> {
- let passphrase: MiniserveConfig = *req.state();
- // let passphrase = req.state().auth;
+impl Middleware<MiniserveConfig> for Auth {
+ fn response(&self, req: &mut HttpRequest<MiniserveConfig>, mut resp: HttpResponse) -> Result<Response> {
+ let passphrase = &req.state().auth;
if passphrase.is_some() {
- println!("{}", passphrase.unwrap());
- println!("{}", req.headers_mut()[header::AUTHORIZATION].to_str().unwrap());
+ println!("{:?}", passphrase);
+ println!("{:?}", req.headers().get(header::AUTHORIZATION));
}
resp.headers_mut().insert(header::WWW_AUTHENTICATE, header::HeaderValue::from_static("Basic realm=\"lol\""));
*resp.status_mut() = StatusCode::UNAUTHORIZED;