MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / handle_callback_request

Function handle_callback_request

crates/openshell-cli/src/auth.rs:297–391  ·  view source on GitHub ↗
(
    req: Request<Incoming>,
    state: Arc<CallbackServerState>,
)

Source from the content-addressed store, hash-verified

295}
296
297async fn handle_callback_request(
298 req: Request<Incoming>,
299 state: Arc<CallbackServerState>,
300) -> CallbackResponse {
301 let method = req.method().clone();
302 let path = req.uri().path().to_string();
303 debug!(method = %method, path = %path, "callback request received");
304
305 let allowed_origin = state.allowed_origin.as_deref();
306 if path != "/callback" {
307 return empty_response(StatusCode::NOT_FOUND, allowed_origin);
308 }
309
310 if let Some(expected_origin) = allowed_origin {
311 let request_origin = req
312 .headers()
313 .get(ORIGIN)
314 .and_then(|value| value.to_str().ok());
315 if request_origin != Some(expected_origin) {
316 debug!(
317 request_origin = ?request_origin,
318 allowed_origin = expected_origin,
319 "callback origin mismatch"
320 );
321 let _ = state.take_sender();
322 return json_response(
323 StatusCode::FORBIDDEN,
324 allowed_origin,
325 r#"{"ok":false,"error":"origin not allowed"}"#,
326 );
327 }
328 }
329
330 if method == Method::OPTIONS {
331 return empty_response(StatusCode::NO_CONTENT, allowed_origin);
332 }
333
334 if method != Method::POST {
335 return json_response(
336 StatusCode::METHOD_NOT_ALLOWED,
337 allowed_origin,
338 r#"{"error":"method not allowed"}"#,
339 );
340 }
341
342 let body = match req.into_body().collect().await {
343 Ok(body) => body.to_bytes(),
344 Err(error) => {
345 debug!(error = %error, "failed to read callback body");
346 let _ = state.take_sender();
347 return json_response(
348 StatusCode::BAD_REQUEST,
349 allowed_origin,
350 r#"{"ok":false,"error":"invalid request body"}"#,
351 );
352 }
353 };
354

Callers 1

run_callback_serverFunction · 0.85

Calls 6

empty_responseFunction · 0.85
json_responseFunction · 0.85
pathMethod · 0.80
getMethod · 0.45
take_senderMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected