fix rustfmt formatting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
15
src/api.rs
15
src/api.rs
@@ -604,7 +604,10 @@ async fn list_services(State(ctx): State<Arc<ServerCtx>>) -> Json<Vec<ServiceRes
|
|||||||
let tld = &ctx.proxy_tld;
|
let tld = &ctx.proxy_tld;
|
||||||
|
|
||||||
// Run all health checks concurrently
|
// Run all health checks concurrently
|
||||||
let health_futures: Vec<_> = entries.iter().map(|(_, port)| check_health(*port)).collect();
|
let health_futures: Vec<_> = entries
|
||||||
|
.iter()
|
||||||
|
.map(|(_, port)| check_health(*port))
|
||||||
|
.collect();
|
||||||
let health_results = futures::future::join_all(health_futures).await;
|
let health_results = futures::future::join_all(health_futures).await;
|
||||||
|
|
||||||
let results: Vec<_> = entries
|
let results: Vec<_> = entries
|
||||||
@@ -628,7 +631,10 @@ async fn create_service(
|
|||||||
|
|
||||||
// Validate name: alphanumeric + hyphens only, 1-63 chars
|
// Validate name: alphanumeric + hyphens only, 1-63 chars
|
||||||
if name.is_empty() || name.len() > 63 {
|
if name.is_empty() || name.len() > 63 {
|
||||||
return Err((StatusCode::BAD_REQUEST, "name must be 1-63 characters".into()));
|
return Err((
|
||||||
|
StatusCode::BAD_REQUEST,
|
||||||
|
"name must be 1-63 characters".into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') {
|
if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') {
|
||||||
return Err((
|
return Err((
|
||||||
@@ -655,10 +661,7 @@ async fn create_service(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn remove_service(
|
async fn remove_service(State(ctx): State<Arc<ServerCtx>>, Path(name): Path<String>) -> StatusCode {
|
||||||
State(ctx): State<Arc<ServerCtx>>,
|
|
||||||
Path(name): Path<String>,
|
|
||||||
) -> StatusCode {
|
|
||||||
if name.eq_ignore_ascii_case("numa") {
|
if name.eq_ignore_ascii_case("numa") {
|
||||||
return StatusCode::FORBIDDEN;
|
return StatusCode::FORBIDDEN;
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/proxy.rs
12
src/proxy.rs
@@ -48,9 +48,7 @@ pub async fn start_proxy(ctx: Arc<ServerCtx>, port: u16, tld: &str) {
|
|||||||
tld_suffix: format!(".{}", tld),
|
tld_suffix: format!(".{}", tld),
|
||||||
};
|
};
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new().fallback(any(proxy_handler)).with_state(state);
|
||||||
.fallback(any(proxy_handler))
|
|
||||||
.with_state(state);
|
|
||||||
|
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
@@ -62,10 +60,7 @@ fn extract_host(req: &Request) -> Option<String> {
|
|||||||
.map(|h| h.split(':').next().unwrap_or(h).to_lowercase())
|
.map(|h| h.split(':').next().unwrap_or(h).to_lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn proxy_handler(
|
async fn proxy_handler(State(state): State<ProxyState>, req: Request) -> axum::response::Response {
|
||||||
State(state): State<ProxyState>,
|
|
||||||
req: Request,
|
|
||||||
) -> axum::response::Response {
|
|
||||||
let hostname = match extract_host(&req) {
|
let hostname = match extract_host(&req) {
|
||||||
Some(h) => h,
|
Some(h) => h,
|
||||||
None => {
|
None => {
|
||||||
@@ -179,8 +174,7 @@ async fn handle_upgrade(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Return 101 to client with the backend's upgrade headers
|
// Return 101 to client with the backend's upgrade headers
|
||||||
let mut resp = axum::response::Response::builder()
|
let mut resp = axum::response::Response::builder().status(StatusCode::SWITCHING_PROTOCOLS);
|
||||||
.status(StatusCode::SWITCHING_PROTOCOLS);
|
|
||||||
for (key, value) in &resp_headers {
|
for (key, value) in &resp_headers {
|
||||||
resp = resp.header(key, value);
|
resp = resp.header(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user