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

Function furls_handler

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

Source from the content-addressed store, hash-verified

52}
53
54async fn furls_handler(
55 State(state): State<RefRuntimeState>,
56 Extension(cmd_tx): Extension<Sender<Action>>,
57 req: Request<Body>,
58) -> Result<Response<Body>, ServerError> {
59 tracing::debug!(path = %req.uri().path(), method = %req.method(), "http invocation received");
60
61 let (parts, body) = req.into_parts();
62 let uri = &parts.uri;
63
64 let (function_name, mut path, path_parameters) =
65 extract_path_parameters(uri.path(), &parts.method, &state);
66 tracing::trace!(%function_name, %path, "received request in furls handler");
67
68 if function_name == DEFAULT_PACKAGE_FUNCTION && !state.is_default_function_enabled() {
69 return respond_with_disabled_default_function(&state, false);
70 }
71
72 if function_name != DEFAULT_PACKAGE_FUNCTION {
73 if let Err(binaries) = state.is_function_available(&function_name) {
74 return respond_with_missing_function(&binaries);
75 }
76 }
77
78 let headers = &parts.headers;
79
80 let body = body
81 .collect()
82 .await
83 .map_err(ServerError::DataDeserialization)?
84 .to_bytes();
85 let text_content_type = match headers.get("content-type") {
86 None => true,
87 Some(c) => {
88 let c = c.to_str().unwrap_or_default();
89 c.starts_with("text/") || c.starts_with("application/json")
90 }
91 };
92
93 let (body, is_base64_encoded) = if body.is_empty() {
94 (None, false)
95 } else if text_content_type {
96 let body =
97 String::from_utf8(body.into_iter().collect()).map_err(ServerError::StringBody)?;
98 (Some(body), false)
99 } else {
100 let body = b64::STANDARD.encode(body.into_iter().collect::<Vec<u8>>());
101 (Some(body), true)
102 };
103
104 let query_string_parameters = uri
105 .query()
106 .unwrap_or_default()
107 .parse::<QueryMap>()
108 .unwrap_or_default();
109
110 let cookies = headers.get("cookie").map(|c| {
111 c.to_str()

Callers

nothing calls this directly

Calls 12

extract_path_parametersFunction · 0.85
schedule_invocationFunction · 0.85
is_streaming_responseFunction · 0.85
create_buffered_responseFunction · 0.85
pathMethod · 0.80
is_function_availableMethod · 0.80
getMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected