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

Function callback_response

crates/openshell-cli/src/auth.rs:247–283  ·  view source on GitHub ↗
(
    status: StatusCode,
    allowed_origin: Option<&str>,
    content_type: Option<&str>,
    body: impl Into<Bytes>,
)

Source from the content-addressed store, hash-verified

245type CallbackResponse = Response<Full<Bytes>>;
246
247fn callback_response(
248 status: StatusCode,
249 allowed_origin: Option<&str>,
250 content_type: Option<&str>,
251 body: impl Into<Bytes>,
252) -> CallbackResponse {
253 let mut response = Response::new(Full::new(body.into()));
254 *response.status_mut() = status;
255 let headers = response.headers_mut();
256 if let Some(origin) = allowed_origin {
257 headers.insert(
258 ACCESS_CONTROL_ALLOW_ORIGIN,
259 hyper::header::HeaderValue::from_str(origin).expect("callback origin is valid"),
260 );
261 headers.insert(
262 ACCESS_CONTROL_ALLOW_METHODS,
263 hyper::header::HeaderValue::from_static("POST, OPTIONS"),
264 );
265 headers.insert(
266 ACCESS_CONTROL_ALLOW_HEADERS,
267 hyper::header::HeaderValue::from_static("Content-Type"),
268 );
269 headers.insert(
270 ACCESS_CONTROL_MAX_AGE,
271 hyper::header::HeaderValue::from_static("60"),
272 );
273 headers.insert(VARY, hyper::header::HeaderValue::from_static("Origin"));
274 }
275 if let Some(content_type) = content_type {
276 headers.insert(
277 CONTENT_TYPE,
278 hyper::header::HeaderValue::from_str(content_type)
279 .expect("callback content type is valid"),
280 );
281 }
282 response
283}
284
285fn empty_response(status: StatusCode, allowed_origin: Option<&str>) -> CallbackResponse {
286 callback_response(status, allowed_origin, None, Bytes::new())

Callers 2

empty_responseFunction · 0.85
json_responseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected