mirror of https://github.com/ospab/ostp.git
fix: make handle_subscribe future Send by scoping RwLockReadGuard
This commit is contained in:
parent
45d5d3b39f
commit
987e42d619
|
|
@ -757,20 +757,26 @@ async fn handle_reset_stats(
|
||||||
///
|
///
|
||||||
/// GET /api/subscribe/{key}
|
/// GET /api/subscribe/{key}
|
||||||
/// Response: JSON client config or ostp:// share link (via Accept header)
|
/// Response: JSON client config or ostp:// share link (via Accept header)
|
||||||
|
|
||||||
async fn handle_subscribe(
|
async fn handle_subscribe(
|
||||||
State(state): State<ApiState>,
|
State(state): State<ApiState>,
|
||||||
Path(key): Path<String>,
|
Path(key): Path<String>,
|
||||||
headers: axum::http::HeaderMap,
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> axum::response::Response {
|
||||||
// Validate that the key exists
|
use axum::response::IntoResponse;
|
||||||
let keys = state.access_keys.read().unwrap();
|
|
||||||
if !keys.contains_key(&key) {
|
// Validate that the key exists in a tightly scoped block to drop the guard
|
||||||
|
let key_exists = {
|
||||||
|
let keys = state.access_keys.read().unwrap();
|
||||||
|
keys.contains_key(&key)
|
||||||
|
};
|
||||||
|
|
||||||
|
if !key_exists {
|
||||||
return (StatusCode::NOT_FOUND, Json(serde_json::json!({
|
return (StatusCode::NOT_FOUND, Json(serde_json::json!({
|
||||||
"ok": false,
|
"ok": false,
|
||||||
"error": "invalid access key"
|
"error": "invalid access key"
|
||||||
})));
|
}))).into_response();
|
||||||
}
|
}
|
||||||
drop(keys);
|
|
||||||
|
|
||||||
let accept = headers.get("accept")
|
let accept = headers.get("accept")
|
||||||
.and_then(|v| v.to_str().ok())
|
.and_then(|v| v.to_str().ok())
|
||||||
|
|
@ -791,7 +797,7 @@ async fn handle_subscribe(
|
||||||
return (StatusCode::OK, Json(serde_json::json!({
|
return (StatusCode::OK, Json(serde_json::json!({
|
||||||
"ok": true,
|
"ok": true,
|
||||||
"data": link
|
"data": link
|
||||||
})));
|
}))).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default: return full client config JSON
|
// Default: return full client config JSON
|
||||||
|
|
@ -822,7 +828,7 @@ async fn handle_subscribe(
|
||||||
(StatusCode::OK, Json(serde_json::json!({
|
(StatusCode::OK, Json(serde_json::json!({
|
||||||
"ok": true,
|
"ok": true,
|
||||||
"data": config
|
"data": config
|
||||||
})))
|
}))).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── DNS API Handlers ──────────────────────────────────────────────────────────
|
// ── DNS API Handlers ──────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue