mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
fix the prefix
This commit is contained in:
parent
47e30683cb
commit
ff2a1ad269
1 changed files with 12 additions and 7 deletions
|
@ -28,8 +28,8 @@ type HttpBody = http_body_util::Full<hyper::body::Bytes>;
|
||||||
#[command(version = clap::crate_version!())]
|
#[command(version = clap::crate_version!())]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// URL prefix the server should serve on
|
/// URL prefix the server should serve on
|
||||||
#[arg(long, default_value = "")]
|
#[arg(long)]
|
||||||
prefix: String,
|
prefix: Option<String>,
|
||||||
/// Port the server should bind to
|
/// Port the server should bind to
|
||||||
#[arg(long, short, default_value = "4000")]
|
#[arg(long, short, default_value = "4000")]
|
||||||
port: String,
|
port: String,
|
||||||
|
@ -117,13 +117,18 @@ async fn main() -> Result<(), Error> {
|
||||||
|
|
||||||
let socket = bind(&addr, opt.unix_socket).await?;
|
let socket = bind(&addr, opt.unix_socket).await?;
|
||||||
|
|
||||||
let prefix = if opt.prefix.starts_with('/') {
|
let prefix = if let Some(prefix) = opt.prefix {
|
||||||
opt.prefix
|
match (prefix.starts_with('/'), prefix.ends_with('/')) {
|
||||||
|
(true, true) => prefix,
|
||||||
|
(true, false) => prefix + "/",
|
||||||
|
(false, true) => "/".to_string() + &prefix,
|
||||||
|
(false, false) => "/".to_string() + &prefix + "/",
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
"/".to_string() + &opt.prefix
|
"/".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("listening on `{}`", addr);
|
println!("listening on `{}` with prefix `{}`", addr, prefix);
|
||||||
while let Ok((stream, addr)) = socket.accept().await {
|
while let Ok((stream, addr)) = socket.accept().await {
|
||||||
let prefix = prefix.clone();
|
let prefix = prefix.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
@ -155,7 +160,7 @@ async fn accept_http(
|
||||||
{
|
{
|
||||||
let (res, fut) = upgrade::upgrade(&mut req)?;
|
let (res, fut) = upgrade::upgrade(&mut req)?;
|
||||||
|
|
||||||
if uri == "/" {
|
if uri.is_empty() {
|
||||||
tokio::spawn(async move { accept_ws(fut, addr.clone(), block_local).await });
|
tokio::spawn(async move { accept_ws(fut, addr.clone(), block_local).await });
|
||||||
} else if let Some(uri) = uri.strip_prefix('/').map(|x| x.to_string()) {
|
} else if let Some(uri) = uri.strip_prefix('/').map(|x| x.to_string()) {
|
||||||
tokio::spawn(async move { accept_wsproxy(fut, uri, addr.clone(), block_local).await });
|
tokio::spawn(async move { accept_wsproxy(fut, uri, addr.clone(), block_local).await });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue