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

Function proxy_to_endpoint

crates/openshell-server/src/service_routing.rs:209–408  ·  view source on GitHub ↗
(
    state: Arc<ServerState>,
    mut req: Request<Body>,
    sandbox_name: String,
    service_name: String,
)

Source from the content-addressed store, hash-verified

207}
208
209async fn proxy_to_endpoint(
210 state: Arc<ServerState>,
211 mut req: Request<Body>,
212 sandbox_name: String,
213 service_name: String,
214) -> Result<Response<Body>, ServiceRouteError> {
215 let endpoint = match load_endpoint(&state.store, &sandbox_name, &service_name).await {
216 Ok(endpoint) => endpoint,
217 Err(err) => {
218 emit_service_http_failure(&state, &req, &sandbox_name, &service_name, None, &err);
219 return Err(err);
220 }
221 };
222 if !endpoint.domain || endpoint.target_port == 0 || endpoint.target_port > u32::from(u16::MAX) {
223 let err = ServiceRouteError::endpoint_unavailable();
224 emit_service_http_failure(
225 &state,
226 &req,
227 &sandbox_name,
228 &service_name,
229 Some(&endpoint),
230 &err,
231 );
232 return Err(err);
233 }
234
235 let sandbox = match state
236 .store
237 .get_message::<Sandbox>(&endpoint.sandbox_id)
238 .await
239 {
240 Ok(Some(sandbox)) => sandbox,
241 Ok(None) => {
242 let err = ServiceRouteError::endpoint_unavailable();
243 emit_service_http_failure(
244 &state,
245 &req,
246 &sandbox_name,
247 &service_name,
248 Some(&endpoint),
249 &err,
250 );
251 return Err(err);
252 }
253 Err(err) => {
254 warn!(error = %err, sandbox_id = %endpoint.sandbox_id, "sandbox service routing: failed to load sandbox");
255 let route_err = ServiceRouteError::internal_error();
256 emit_service_http_failure(
257 &state,
258 &req,
259 &sandbox_name,
260 &service_name,
261 Some(&endpoint),
262 &route_err,
263 );
264 return Err(route_err);
265 }
266 };

Callers 1

Calls 12

load_endpointFunction · 0.85
upstream_uri_pathFunction · 0.85
is_websocket_upgradeFunction · 0.85
build_upstream_requestFunction · 0.85
object_idMethod · 0.80
send_requestMethod · 0.80
into_partsMethod · 0.80
spawnFunction · 0.50
phaseMethod · 0.45

Tested by

no test coverage detected