MCPcopy Index your code
hub / github.com/cargo-lambda/cargo-lambda / invoke_handler

Function invoke_handler

crates/cargo-lambda-watch/src/trigger_router.rs:196–232  ·  view source on GitHub ↗
(
    State(state): State<RefRuntimeState>,
    Extension(cmd_tx): Extension<Sender<Action>>,
    Path(function_name): Path<String>,
    req: Request<Body>,
)

Source from the content-addressed store, hash-verified

194}
195
196async fn invoke_handler(
197 State(state): State<RefRuntimeState>,
198 Extension(cmd_tx): Extension<Sender<Action>>,
199 Path(function_name): Path<String>,
200 req: Request<Body>,
201) -> Result<Response<Body>, ServerError> {
202 tracing::debug!(%function_name, "invocation received");
203
204 if function_name == DEFAULT_PACKAGE_FUNCTION && !state.is_default_function_enabled() {
205 tracing::error!(available_functions = ?state.initial_functions, "the default function route is disabled, use /lambda-url/:function_name to trigger a function call");
206 return respond_with_disabled_default_function(&state, true);
207 }
208
209 if function_name != DEFAULT_PACKAGE_FUNCTION {
210 if let Err(binaries) = state.is_function_available(&function_name) {
211 return respond_with_missing_function(&binaries);
212 }
213 }
214
215 let resp = schedule_invocation(&cmd_tx, function_name, req).await?;
216 let status_code = resp
217 .extensions()
218 .get::<StatusCode>()
219 .cloned()
220 .unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
221
222 let (info, mut body) = resp.into_parts();
223
224 let mut builder = Response::builder().status(status_code);
225
226 if is_streaming_response(&info.headers) && status_code == StatusCode::OK {
227 let status = create_streaming_response(&mut builder, &mut body).await?;
228 builder = builder.status(status);
229 }
230
231 builder.body(body).map_err(ServerError::ResponseBuild)
232}
233
234async fn invoke_with_response_stream_handler(
235 State(state): State<RefRuntimeState>,

Callers

nothing calls this directly

Tested by

no test coverage detected