Skip to main content

proto_request_with_ctx

Function proto_request_with_ctx 

Source
pub async fn proto_request_with_ctx<Req, Rsp>(
    state: &RestState,
    proto_id: u32,
    json_body: Option<Value>,
    idempotency_key: Option<String>,
    ctx: Option<&CallerContext>,
) -> Result<Json<Value>, (StatusCode, Json<Value>)>
Expand description

codex 0522 F1 v1.4.106 (推荐 API): 带 CallerContext 的 proto_request.

proto_request_with_idempotency / proto_request_with_filter 的关系: 后两者只接 idempotency_keyallowed_acc_ids 单一维度, 本函数接完整 CallerContext (含 key_id + allowed_acc_ids), 把 caller scope 同时 接到三个下游消费点:

  1. IncomingRequest.caller_allowed_acc_ids (dispatch handler 的 per-acc enforce, defense-in-depth)
  2. IncomingRequest.caller_key_id (per-key 配额 / cleanup / 审计入口)
  3. FilterRegistry::apply (响应 acc_list 过滤)

任一接错 → dispatch handler 看到 None 就 silent bypass (codex F1 audit 实锤的 v1.4.105 之前 REST regression).

ctx = None 等价 legacy mode (无 caller key, 无 acc 限制) — 通常仅 测试 / 显式 unauthenticated route 用. 真 route handler 应该总是构 ctx 从 Extension<Arc<KeyRecord>> 抽出来 (CallerContext::from_key_record).