Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 136 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ gloo = "0.11.0"
gloo-file = "0.3.0"
humansize = "2.1.3"
http = "1.1.0"
http-auth-basic = "0.3.3"
http-body-util = "0.1"
hyper = "1.4"
hyper-util = "0.1.9"
Expand All @@ -44,8 +43,9 @@ serde_json = "1.0.128"
tokio = "1.40"
tokio-util = "0.7.12"
toml = "0.8.19"
tower-http = "0.6.1"
tower = "0.5.1"
tower-http = "0.6.1"
tower-layer = "0.3.3"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
web-sys = "0.3.72"
Expand Down
10 changes: 9 additions & 1 deletion crates/http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ keywords = ["configurable", "http", "server", "serve", "static"]
license = "MIT OR Apache-2.0"
readme = "README.md"

[[bin]]
name = "http-server"
path = "src/bin/main.rs"

[lib]
name = "http_server_rs"
path = "src/lib.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -18,7 +26,6 @@ async-trait = { workspace = true }
bytes = { workspace = true }
clap = { workspace = true, features = ["env", "derive", "std"] }
http = { workspace = true }
http-auth-basic = { workspace = true }
http-body-util = { workspace = true }
hyper = { workspace = true }
hyper-util = { workspace = true, features = ["full"] }
Expand All @@ -27,6 +34,7 @@ local-ip-address = { workspace = true }
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "signal", "macros"] }
tower-http = { workspace = true, features = ["cors"] }
tower = { workspace = true, features = ["util"] }
tower-layer = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use clap::Parser;
use tokio::runtime::Builder;
use tracing::{error, info};

use crate::config::Config;
use crate::server::Server;
use http_server_rs::server::config::Config;
use http_server_rs::server::Server;

const THREAD_NAME: &str = "http-server";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
pub mod cli;
pub mod config;
pub mod plugin;
pub mod server;

use anyhow::Result;
use clap::Parser;
Expand Down
10 changes: 0 additions & 10 deletions crates/http-server/src/config.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/http-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod server;
37 changes: 37 additions & 0 deletions crates/http-server/src/server/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::net::IpAddr;
use std::str::FromStr;

use anyhow::{bail, Error, Result};

#[derive(Clone, Debug)]
pub struct Config {
/// The IP address to bind to.
pub host: IpAddr,
/// The port to bind to.
pub port: u16,
/// Enable CORS with a permissive policy.
pub cors: bool,
}

#[derive(Clone, Debug)]
pub struct BasicAuth {
pub username: String,
pub password: String,
}

impl FromStr for BasicAuth {
type Err = Error;

fn from_str(s: &str) -> Result<Self> {
let parts = s.split(":").collect::<Vec<&str>>();

if parts.len() != 2 {
bail!("Expected a string with a colon to separe username and password for Basic Authentication.");
}

Ok(BasicAuth {
username: parts[0].into(),
password: parts[1].into(),
})
}
}
Loading
Loading